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:
protected/componentsmyButtonColumn 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:
Use it like CGridButton
$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)', ), ), ));
Total 4 comments
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.
tnx for help
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 :
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(); ....i was searching the yii docs for something like this.
Leave a comment
Please login to leave your comment.