1

我在这里关注文档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;
}

我遇到的问题是返回值被编码所以我得到 <a href=...>

有没有办法告诉 CGridView 不要对值进行编码?

谢谢

4

3 回答 3

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',
),
于 2012-05-28T07:38:30.963 回答
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'),

), ), ));

于 2012-05-28T08:15:01.757 回答
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....???
于 2012-11-07T13:35:46.523 回答