I'm following the documents here http://www.yiiframework.com/wiki/278/cgridview-render-customized-complex-datacolumns/

So I have the following in view

$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'),
    ),
),
));

And here is the editLink function in model

public function editLink($data, $row) {
    $link = '';
    if ($data->is_draft) {
        $link = '<a href="customer/update/'.$data->id.'">Edit</a>';
    }
    return $link;
}

The problem that I'm having is that the return value is encoded so I get <a href=...>

Is there a way to tell CGridView not to encode the value?

Thanks

有帮助吗?

解决方案

Solution A:

array(
    'name'=>'Edit',
    'type' => 'raw',
    'value'=>array($model, 'editLink'),
),

B: (not good enough)

array(
    'name' => 'Edit',
    'class' => 'CLinkColumn',
    'urlExpression' => '$data->is_draft ? "customer/update/{$data->id}" : "#disabled"',
    'label' => 'edit',
),

其他提示

try this ..

$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'),

), ), ));

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....???
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top