CButtonColumn visible property for standard buttons

The new CButtonCOlumn in Yii 1.1.1 has a visible property but only for custom buttons, would be nice to implement the visible property for the default buttons (delete, view, update)… something like updateButtonVisible=’…’, etc…

I Agree,

This is my solution :

Rename file CButtonColumn.php to RelixerCButtonColumn.php, then Add :




	 //default visible

	public $viewVisible='true';

	public $updateVisible='true';

	public $deleteVisible='true';



then change code from :




		foreach(array('view','update','delete') as $id)

		{

			$button=array(

				'label'=>$this->{$id.'ButtonLabel'},

				'url'=>$this->{$id.'ButtonUrl'},

				'imageUrl'=>$this->{$id.'ButtonImageUrl'},

				'options'=>$this->{$id.'ButtonOptions'},

			);

			if(isset($this->buttons[$id]))

				$this->buttons[$id]=array_merge($button,$this->buttons[$id]);

			else

				$this->buttons[$id]=$button;

		}



became :




		foreach(array('view','update','delete') as $id)

		{

			$button=array(

				'label'=>$this->{$id.'ButtonLabel'},

				'url'=>$this->{$id.'ButtonUrl'},

				'imageUrl'=>$this->{$id.'ButtonImageUrl'},

				'options'=>$this->{$id.'ButtonOptions'},

				'visible'=>$this->{$id.'Visible'}, //-->THIS IS NEW CODE

			);

			if(isset($this->buttons[$id]))

				$this->buttons[$id]=array_merge($button,$this->buttons[$id]);

			else

				$this->buttons[$id]=$button;

		}



Then How to use in CGridView :




		array(

		 	'header'=>'Action',

			'class'=>'RelixerCButtonColumn',

			'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfuly"); }',			

			'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",array("id"=>$data->uom_code))',

			'updateVisible'=>Yii::app()->user->checkAccess('Uom.Index'), //you can change this by true or false

			'updateVisible'=>Yii::app()->user->checkAccess('Uom.Update'),

			'updateVisible'=>Yii::app()->user->checkAccess('Uom.Delete'),

			//'visible'=>Yii::app()->user->checkAccess('Uom.Index'),

		),



Note that this thread is very old…

There is no need for extending these properties…

You can just assign the visible properties of the "default" buttons… like…




'buttons'=>array(

   'update'=>array(

  	'visible'=>your expression

   )

)



Thanks for Information.