array('name' => '已删除'), 1 => array('name' => '正常', 'filter' => true) ); protected $auto_fields = array('auth_item'); public function __construct($scenario='insert'){ parent::__construct($scenario); $this->onBeforeSave = function($event){ //根据url规则得到对应的权限字符串 $model = $event->sender; $url = $model->url; $route = 'no_route'; $auth_item = ''; if (preg_match('/(&|\?)r=([^&]+)/', $url, $matches)){ $route = $matches[2]; } if (($ca = Yii::app()->createController($route)) !== null){ list($controller, $action) = $ca; $za = new ZAuth(); $auth_item = $za->getAuthItem($controller, $action); } $model->auth_item = $auth_item; }; } public static function model($className=__CLASS__) { return parent::model($className); } public function getCollectionName() { return 'admin_menu'; } }