在 CGridView 中添加列作为链接 [英] Add column as link in CGridView
本文介绍了在 CGridView 中添加列作为链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要向我的 gridview 添加链接,此链接将调用带有参数的操作,例如user_id 和 course_id .
所以我写了这段代码
I need to add link to my gridview this link will call action with parameters like
user_id and course_id .
so i wrote this code
查看:
<?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- 我如何访问列值
1- Why return this error ? 2- how I can access to column value
提前致谢
推荐答案
'value' => "CHtml::link('Add',array('packages/add','user_id'=>$user_id,'course_id'=>\$data->course_id))",
您正在使用 ""
来引用您的字符串,因此您需要对 $data
上的 $
进行转义,因此它读取为 <代码>\$data.
You are using ""
to quote your string, so you need to escape the $
on $data
, so it reads as \$data
.
这篇关于在 CGridView 中添加列作为链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文