我需要添加链接到我的gridview这个链接将调用带有参数的动作
user_id和course_id。
所以我写了这段代码
查看:
<?php
$cmodel=new Courses;
$user_id=intval($_GET['user_id']);
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'courses-grid',
'dataProvider'=>$cmodel->searchCources($user_id),
'filter'=>$cmodel,
'columns'=>array(
'course_id',
'name_ar',
'name_en',
'code',
't_time',
array(
'name' => 't_time',
'value' => "CHtml::link('Add',array('packages/add','user_id'=>$user_id,'course_id'=>$data->course_id))",
'type' => 'raw',
)
,
/*
'req',
'aud',
'targets',
'programs',
'criterion',
'section_id',
'acc',
'en',
'ar',
'fr',
'image',
*/
)));
?>
型号:
<?php
...
public function searchCources($user_id)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('course_id',$this->course_id);
$criteria->compare('name_ar',$this->name_ar,true);
$criteria->compare('name_en',$this->name_en,true);
$criteria->compare('code',$this->code,true);
$criteria->compare('t_time',$this->t_time);
$criteria->compare('intro',$this->intro,true);
$criteria->compare('req',$this->req,true);
$criteria->compare('aud',$this->aud,true);
$criteria->compare('targets',$this->targets,true);
$criteria->compare('programs',$this->programs,true);
$criteria->compare('criterion',$this->criterion,true);
$criteria->compare('acc',$this->acc);
$criteria->compare('en',$this->en);
$criteria->compare('ar',$this->ar);
$criteria->compare('fr',$this->fr);
$criteria->compare('image',$this->image,true);
$criteria->addCondition(' course_id not in ( select course_id from ict_cpackage where user_id='.$user_id.') ');
return new CActiveDataProvider($this, array(
'criteria'=>$criteria
));
}
...
?>
但是返回此错误:
Undefined variable: data
1-为什么要返回此错误? 2-我如何访问列值
提前致谢
答案 0 :(得分:2)
'value' => "CHtml::link('Add',array('packages/add','user_id'=>$user_id,'course_id'=>\$data->course_id))",
您正在使用""
来引用字符串,因此您需要转义$
上的$data
,因此它显示为\$data
。