R
R
raycheel2014-02-03 21:14:11
Yii
raycheel, 2014-02-03 21:14:11

How to inject ajaxLink inside CMenu widget?

Please tell me how to embed ajaxlink in the menu

<?php $this->widget('zii.widgets.CMenu',array(
    'items'=>array(
        array('label'=>'Home', 'url'=>array('/site/index')),
        array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
        array('label'=>'Contact', 'url'=>array('/site/contact')),
        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) ),
    )); ?>

The ajaxLink itself looks like this:
CHtml::ajaxLink('Вход', $this->createUrl('user/login'),
                  array('update' => '#exampleModal'),
                  array('id'=>'login-btn','class'=>'btn btn-success btn-md','onclick' => '$("#exampleModal").arcticmodal();')
                  );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhuravlev, 2014-02-04
@Zhuravljov

Try something like:

<?php $this->widget('zii.widgets.CMenu', array(
    'items' => array(
        ...
        array(
            'label' => 'Вход',
            'url' => array('/site/login'),
            'visible' => Yii::app()->user->isGuest,
            'linkOptions' => array(
                'ajax' => array('update' => '#exampleModal'),
                'id' => 'login-btn',
                'onclick' => '$("#exampleModal").arcticmodal();',
            ),
        ),
        ...
    ),
)); ?>

Both CMenu and CHtml::ajaxLink() use CHtml::clientChange() at the code level which handles the ajax parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question