There are several controllers. It is necessary that, before processing them, some script should work, in which, in case of passing the condition, redirect worked.
I tried to implement a trace. way
In the frontend / config / main.php, the BeforeController component added to the bootstrap field BeforeController
'bootstrap' => ['log','BeforeController'], BeforeController itself:
class BeforeController extends \yii\base\Component { public function init() { if(Yii::$app->user->isGuest) return parent::init(); $user = User::findOne(Yii::$app->user->id); if(!$user->phone_confirmed_at) return Yii::$app->response->redirect(['sms/activate']); return parent::init(); } } The problem is that if you refresh the sms/activate page, there will be a permanent redirect. But do something like:
if(Yii::$app->controller->id == 'sms') return true; I can not, because In the controller, we have not yet hit. What are the alternatives to this solution?