I'm aware there's a similar post to this but just to confirm my understanding.
I just start using Yii2 PHP. I've used dektrium/yii2-user that can login and register. I want to do a beforeAction() to check logged user auth.key if exist in database (XAMPP MYSQL). Below is the code I want to performed on.
//Action direct to json.php.
public function actionJson()
{
return $this->render('json');
}
If the statement true will direct to the page, else shows a alert error.
I know the exact code is
public function beforeAction($action){}
What I'm confused on is where do I actually put beforeAction() at.
Where to place it?
You must place it inside your login controller (LoginController.php) class. Remember to call the parent inside the function as :
Then all the actions from that controller will use your custom beforeAction function.