Search code examples
phpyiicgridview

CGridView encoded the value


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

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