1

我是 yii 的新手。在我的项目中,我想通过Cmenu栏传递参数

 array('label' => 'Category', 'url' => array('site/catagory', 'visible' => !Yii::app()->user->isGuest),

并且参数传递是从下拉列表中获取的,该下拉列表也在下拉列表的导航条代码中

  $site = Site::model()->findAll();  
  $data = CHtml::listData($site, 'id', 'type');  
  echo $form->dropDownList($siteid, 'selectedsiteid', $data, array('class' => "form-control"));

它位于菜单栏之后。请有人帮助我。
提前致谢...

4

2 回答 2

0

不建议使用 onclick + 全局函数/变量。随着时间的推移,事情会变得一团糟。

使用 jQuery 的稍微优雅的解决方案。看看逻辑是如何与视图分离的。


PHP:

array(
    'label' => 'Category',
    'url' => '#',
    'linkOptions' => array( 'id' => 'menu-link' ),
    'visible' => ! Yii::app( )->user->isGuest
),


Javascript:

$( document ).ready(
    function ( )
    {
         $( '#menu-link' ).click(
             function ( )
             {
                 var sid = $( '#Site_selectedsiteid' ).val( );
                 var currentURL = window.location.pathname;
                 var newUrl = currentURL.substring( 0, currentURL.lastIndexOf( '/' ) + 1 );
                 window.location.href = newUrl + 'category?sid=' + sid;
             }
         );
     }
);
于 2014-02-05T12:19:28.297 回答
0

我已经通过使用javascript解决了它,菜单按钮代码被

array('label' => 'Category', 'url' => '#','linkOptions'=>array('onclick'=>'getsid()'),'visible' => !Yii::app()->user->isGuest),

称为java脚本

function getsid()
{
$sid=$('#Site_selectedsiteid').val();
window.location.href = window.location.pathname.substring( 0, window.location.pathname.lastIndexOf( '/' ) + 1 ) + 'catagory?sid=' + $sid;
}

于 2014-02-05T04:37:23.183 回答