Yii2 check if user is logged before every page [duplicate]
问题 This question already has answers here : Yii2 global filter/behavior to force user to authenticate first (2 answers) Closed 4 years ago . I am new to Yii2. How can i check if user is logged in or not ? If user is not logged in then it should redirect to login page. Is there any global solution? 回答1: I set the 'access' behaviors in all controllers public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className(), 'only' => ['logout', 'signup'], 'rules' => [ [ 'actions'