我在这里关注文件http://www.yiiframework.com/wiki/278/cgridview-render-customized-complex-datacolumns/
所以我在视图中有以下内容
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'item-table-grid',
'dataProvider'=>$model->search(),
'itemsCssClass'=>'item-table-grid',
'columns'=>array(
'customer_name',
array(
'name'=>'Edit',
'value'=>array($model, 'editLink'),
),
),
));
这是模型中的editLink函数
public function editLink($data, $row) {
$link = '';
if ($data->is_draft) {
$link = '<a href="customer/update/'.$data->id.'">Edit</a>';
}
return $link;
}
我遇到的问题是返回值已编码,因此我得到&lt; a href = ...&gt;
有没有办法告诉CGridView不要对值进行编码?
由于
答案 0 :(得分:5)
解决方案A:
array(
'name'=>'Edit',
'type' => 'raw',
'value'=>array($model, 'editLink'),
),
B :(还不够好)
array(
'name' => 'Edit',
'class' => 'CLinkColumn',
'urlExpression' => '$data->is_draft ? "customer/update/{$data->id}" : "#disabled"',
'label' => 'edit',
),
答案 1 :(得分:2)
试试这个..
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'item-table-grid',
'dataProvider'=>$model->search(),
'itemsCssClass'=>'item-table-grid',
'columns'=>array(
'customer_name',
array(
'name'=>'Edit',
'type' => 'raw',
'value'=>array($model, 'editLink'),
), ) ));
答案 2 :(得分:0)
my code in CGridView
array(
'name'=>'Post Content',
'value'=>array($model,'postContent'),
'type'=>'html',
'htmlOptions'=>array('width'=>'380'),
),
in Model I have the following method
public function postContent($data){
echo $data->content;
}
it works fine but when i click on another page of my pagination
then it doesn't works means it work only on Index page first time opened...
plz any solution....???