简体   繁体   中英

Add confirmation to Yii Menu items

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.

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("آیا برای خروج از سایت اطمینان دارید؟")') 
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM