因为项目需要,需要给产品添加上架下架的功能,而最方便的方案就是在产品管理界面admin.php下给
::import('zii.widgets.grid.CButtonColumn');class PButtonColumn extends CButtonColumn{public $template='{view} {update} {publish} {offline} {delete}';public $publishButtonLabel;public $publishButtonImageUrl;public $publishButtonUrl='Yii::app()->controller->createUrl("publish",array("id"=>$data->primaryKey))';public $publishButtonOptions=array('class'=>'publish');public $afterPublish;public $offlineButtonLabel;public $offlineButtonImageUrl;public $offlineButtonUrl='Yii::app()->controller->createUrl("offline",array("id"=>$data->primaryKey))';public $offlineButtonOptions=array('class'=>'offline');public $offlineConfirmation;public $afterOffline;protected function initDefaultButtons(){if($this->viewButtonLabel===null)$this->viewButtonLabel='查看';if($this->updateButtonLabel===null)$this->updateButtonLabel='修改';if($this->publishButtonLabel===null)$this->publishButtonLabel='发布';if($this->offlineButtonLabel===null)$this->offlineButtonLabel='下架';if($this->deleteButtonLabel===null)$this->deleteButtonLabel='删除';if($this->viewButtonImageUrl===null)$this->viewButtonImageUrl=$this->grid->baseScriptUrl.'/view.png';if($this->updateButtonImageUrl===null)$this->updateButtonImageUrl=$this->grid->baseScriptUrl.'/update.png';if($this->publishButtonImageUrl===null)$this->publishButtonImageUrl = $this->grid->baseScriptUrl.'/publish.png';if($this->offlineButtonImageUrl===null)$this->offlineButtonImageUrl = $this->grid->baseScriptUrl.'/offline.png';if($this->deleteButtonImageUrl===null)$this->deleteButtonImageUrl=$this->grid->baseScriptUrl.'/delete.png';if($this->offlineConfirmation===null)$this->offlineConfirmation='您确定要下架这个产品吗?';if($this->deleteConfirmation===null)$this->deleteConfirmation='您确定要删除这个产品吗?这可能会造成与其相关联的信息的丢失,请慎重操作!';foreach(array('view','update','publish','offline','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;}if(!isset($this->buttons['publish']['click'])){$confirmation='';if(Yii::app()->request->enableCsrfValidation){$csrfTokenName = Yii::app()->request->csrfTokenName;$csrfToken = Yii::app()->request->csrfToken;$csrf = "nttdata:{ '$csrfTokenName':'$csrfToken' },";}else$csrf = '';if($this->afterPublish===null)$this->afterPublish='function(){}';$this->buttons['publish']['click']=<< 最后要将admin.php中 array( 改成: array( 即可。
'class'=>'CButtonColumn',
),
'class'=>'PButtonColumn',
),