我需要向我的 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-我如何访问列值
提前致谢