1

I have a menu like this in my Yii application:

<?php $this->widget('zii.widgets.CMenu',array(
        'items'=>array(
            array('label'=>'Home', 'url'=>array('/site/index')),

            array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
            array('label'=>'Logout('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest, ))


        ),
    )); ?>

How can I add javascript or Jquery confirmation box to my last menu link? I mean when users click on Logout, javascript box shown and if user click on Ok then it logouts otherwise nothing happen.

Mazdak
  • 771
  • 2
  • 11
  • 24
  • just check by adding `array('confirm' => 'Are you sure?')` – ɹɐqʞɐ zoɹǝɟ May 18 '14 at 12:06
  • I add this: array('label'=>'Home('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest,array('confirm' => 'Are you sure?') ) and nothing happen, even when I check with FireBug nothing added to related anchor tag. Could you tell me exactly where should I add it? – Mazdak May 18 '14 at 12:29

1 Answers1

2

I found it, here is the answer:

array(
'label'=>'خروج ('.Yii::app()->user->name.')', 
'url'=>array('/site/logout'), 
'visible'=>!Yii::app()->user->isGuest,
'linkOptions' => array('onclick'=>'return confirm("آیا برای خروج از سایت اطمینان دارید؟")') 
)
Jonnny
  • 4,939
  • 11
  • 63
  • 93
Mazdak
  • 771
  • 2
  • 11
  • 24