Like, the question has already been answered. But, nevertheless, I would like to answer it in the future.
I am using yii2-app-basic . [ NOTE : The directory structure may differ for yii2-app-advanced .]
My directory structure:
->Root Folder ->assets ->commands . . ->controllers ->SiteController.php ->CommonController.php (New common controller created) ->mail . . ->modules ->users ->controllers ->UsersController.php ->models ->Users.php ->views ->index.php ->Users.php . . .
CommonController.php [Common controller (see directory structure), which will be extended in all controllers, if necessary.]
<?php namespace app\controllers; use Yii; use yii\web\Controller; class CommonController extends Controller { . .
UsersController.php
<?php namespace app\modules\users\controllers; use Yii; . . use app\controllers\CommonController;
So, whenever this UsersController.php controller enters the account, the first init() method will be called, and in the init() method, the CommonController checkLoginAccess() method will receive a call automatically. Thus, whenever a member who does not have access to an account, he automatically logs out .
Hope this helps. Any problem / question, feel free to ask.
source share