Hi there.
I am doing some testing here and there with Yii 1.1.2 before using it in production sites.
My question is about the CGridView generated with the CRUD.
The thing is: it would be great you could render a custom template/partial in the button or the entire cell.
Symfony uses TOO MUCH this approach, and the idea is grabbed from there. What I say is use a very much limited version of that…
Something like (using the Blog demo):
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate' => false,
'columns'=>array(
array(
'name'=>'title',
'type'=>'raw',
'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)'
),
array(
'name'=>'status',
'value'=>'Lookup::item("PostStatus",$data->status)',
'filter'=>Lookup::items('PostStatus'),
),
array(
'name'=>'create_time',
'type'=>'datetime',
'filter'=>false,
),
array(
'class'=>'CButtonColumn',
'template' => '{view}{update}{mydelete}',
'buttons' => array(
'mydelete' => array(
'partial' => '_mydeletebutton' // here my partial, it could access $model or $data, and $row
),
)
),
),
)); ?>
In this case, the partial would look like this (just an useless example):
<span><?php echo $row; ?></span>
<?php echo CHtml::link('Delete', array('delete', 'id' => $model->id)); ?>
In the other case, maybe replace all the cell with a partial:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate' => false,
'columns'=>array(
array(
'name'=>'title',
'type'=>'raw',
'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)'
),
array(
'name'=>'status',
'value'=>'Lookup::item("PostStatus",$data->status)',
'filter'=>Lookup::items('PostStatus'),
),
array(
'name'=>'create_time',
'type'=>'datetime',
'filter'=>false,
),
array(
'class'=>'CButtonColumn',
'partial' => '_mycustomcolumn', // same as before, but replacing the entire cell
),
),
)); ?>
And in this case, the partial would look like this (maybe a bit more useful):
<ul class="grid_actions">
<li><span><?php echo $row; ?></span><?php echo CHtml::link('Update', array('update', 'id' => $model->id)); ?></li>
<li><span><?php echo $row; ?></span><?php echo CHtml::link('Delete', array('delete', 'id' => $model->id)); ?></li>
</ul>
Well…thanks for everything…