restrict view based on user's value in model using rules in controller- yii -
is there way restrict view based on user's input in model in controller? want hide/show own page based on own choice. profile_hide_show values of 'p'=>public, 'f'=>friends, , 'm'=>me
public function accessrules() { return array( array('allow', 'actions'=>array('view'), 'users'=>array('?'), //?based on user's selection in model, ), ); }
the yii access control allows perform basic control before descending local methods of controller.
you can enable access control using 'expression' attribute of access control list. example :
public function accessrules(){ $owner_id = $this->loadmodel()->owner_id; return array( array('allow', 'actions'=>array('action1'), 'expression'=>"{$user->id}=={$owner_id}", ), array('allow', 'actions'=>array('action2'), 'expression'=>'(yii::app()->user->id == ($_get[\'id\']))', ), array('allow', 'actions'=>array('action3'), 'expression'=>'"yii::app()->controller->isenabledbyuser()', ) ); }
if see expression action3, see can call functions return true/false value evaluated expression attribute.
public function isenabledbyuser(){ $user_id = yii::app()->user->id; $user = user::model()->findbypk($user_id); if ($user->show_my_page == 'y') return true; else return false; }
references how view data made user?
Comments
Post a Comment