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 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时