D
D
Dilik Pulatov2017-05-12 12:01:26
Yii
Dilik Pulatov, 2017-05-12 12:01:26

In Yii2, what is the correct way to use $app->runAction()?

Hello!
I have such a problem

public function beforeAction($action){
  $user_action = $action->controller->id.'/'.$action->id;
  if (!in_array($user_action, Yii::$app->user->identity['rols']) ) {
    return $this->redirect(['/admin/default/error']);
  }
  return parent::beforeAction($action);
}

and there the redirect does not work at all .... why? Or in beforekshen it is impossible?
and then did another option
public function beforeAction($action){
  $user_action = $action->controller->id.'/'.$action->id;
  if (!in_array($user_action, Yii::$app->user->identity['rols']) ) {
    return Yii::$app->runAction('/admin/default/error');
  }
  return parent::beforeAction($action);
}

this option doesn't work very well....it just takes that view and displays it...and there the same old address is left in the address bar...
so how can you redirect to the preforexion according to the conditions? or is there another option please let me know

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-05-12
@qonand

Judging by the code, you are trying to make a distinction between user rights, in this case you are reinventing the wheel. Access control filters and RBAC are used to differentiate access rights

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question