NOTE: As of Yii version 1.1.1 the visible attribute is added to the core, so this extension is NOT NEEDED.
myButtonColumn extends CButtonColumn in CGridView and adds the attribute 'visible' to the buttons properties so that the buttons can be different from row to row depending on the evaluation of this attribute.
For the default buttons adds:
- viewButtonVisible
- updateButtonVisible
- deleteButtonVisible.
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the release file under
protected/components
Overview ¶
myButtonColumn extends CButtonColumn in CGridView and adds the attribute 'visible' to the buttons properties so that the buttons can be different from row to row depending on the evaluation of this attribute.
Additionaly, for the default buttons, adds:
- viewButtonVisible
- updateButtonVisible
- deleteButtonVisible
Usage ¶
Use it like CGridButton
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'name',
'type',
array(
'class'=>'myButtonColumn',
'viewButtonVisible'=>'$data->id==Yii::app()->user->id',
'updateButtonVisible'=>'$data->id==Yii::app()->user->id',
'deleteButtonVisible'=>'User::canDelete($data->id)',
),
),
));
?>
Change Log ¶
February 18, 2010 ¶
- Initial release.
Suggestion
Thank you for your exemple.
Default action links doesnt work when the grid is rendered in the contect of a renderPartial with another AR. The links are going to the main view....
So I add this member :
public $baseActionUrl;
And do some stuff before base init()
public function init() if ( !empty( $this->baseActionUrl ) ) { $this->viewButtonUrl = str_replace( '"view"' , '"' . ( $this->baseActionUrl ) . '/view"' , $this->viewButtonUrl ); $this->updateButtonUrl = str_replace( '"update"' , '"' . ( $this->baseActionUrl ) . '/update"' , $this->updateButtonUrl ); $this->deleteButtonUrl = str_replace( '"delete"' , '"' . ( $this->baseActionUrl ) . '/delete"' , $this->deleteButtonUrl ); } parent::init(); ....
nice
i was searching the yii docs for something like this.
tnx
tnx for help
SOLVED: call_user_func_array() expects parameter 1 ...
I had some error
Error 500:
PHP Error [2]
call_user_func_array() expects parameter 1 to be a valid callback, no array or string given (C:\server\www\crm\yii\framework\base\CComponent.php:621)
1 C:\server\www\crm\yii\framework\base\CComponent.php(621): call_user_func_array()
2 C:\server\www\crm\yii\framework\zii\widgets\grid\CButtonColumn.php(306): myButtonColumn->evaluateExpression()
3 C:\server\www\crm\protected\components\myButtonColumn.php(42): myButtonColumn->renderButton()
I modified line 40 like below.
Now everything works fine.
$button['visible']=$this->evaluateExpression("'".$button['visible']."'",array('data'=>$data,'row'=>$row));
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.