dongmeng2509 2012-08-24 08:05
浏览 45
已采纳

Yii zii.widgets.grid.CGridView viewButtonUrl问题

$rid = ""
if( isset( $_GET['rid'] ) {
    $rid = $_GET['rid'];
}

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'guests-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'name',
        'address',
        'contact_numbers',
        'email_addresses',
        /*
        'company_name',
        'company_contact_nos',
        'person_to_notify_emergency',
        'person_to_notify_contact_no',
        */
        array(
            'class'=>'CButtonColumn',
            'viewButtonUrl' => 'Yii::app()->createUrl("guests/view",array("id"=>$data->idGuests,"rid"=>"$rid"))',

        ),
    ),
)); ?>

I'm sure the $rid exist because this is my url

http://localhost/mysite/index.php?r=guests/admin&rid=1

Here's the error: enter image description here

The error is caused by the viewButtonUrl, I know that the reason why $_GET['rid'] has an error because all variables in a CGridView should b in the $model variable.

Is there a way to fix this one? Your help will be greatly appreciated and rewarded!

Thanks!

  • 写回答

1条回答 默认 最新

  • donglan6777 2012-08-24 08:10
    关注

    The problem is that you're using single quotes and thus giving the variable to the CGridView component.

    CGridView then tries to parse the string. However, in CGridView's context, there isn't a variable $rid.

    Use double quotes in this case and escape the double quotes inside the string.

    'Yii::app()->createUrl("guests/view",array("id"=>$data->idGuests,"rid"=>"$rid"))'
    

    Becomes

    "Yii::app()->createUrl(\"guests/view\",array(\"id\"=>\$data->idGuests,\"rid\"=>\"$rid\"))"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来