This method was self-developed by myself. I didn't use the yii filter verification mechanism, but it was finally realized, and I felt very good. Even if I had obsessive-compulsive disorder, haha. As you know, when creating an app, you will automatically create a Controller. php under protectedcomponent, which inherits from the CController,
This method was self-developed by myself. I didn't use the yii filter verification mechanism, but it was finally realized, and I felt very good. Even if I had obsessive-compulsive disorder, haha. As you know, when creating an app, you will automatically create a Controller. php under protected/component. This Controller inherits from CController,
This method was self-developed by myself. I didn't use the yii filter verification mechanism, but it was finally realized, and I felt very good. Even if I had obsessive-compulsive disorder, haha.
As you know, when creating an app, you will automatically create a Controller under protected/component. php, the Controller inherits from the CController, and Gii inherits the controller by default when creating the Controller required by the project. controoler in php, so that we can get down from this controller directly.
The code for reloading the beforeAction function is as follows:
protected function beforeAction($action){if (Yii::app()->user->isGuest) {if(get_class($action->getController()) != 'SiteController' || strtolower($action->getId()) != 'login'){Yii::app()->user->loginRequired() ;}}return parent::beforeAction($action);}
After reading the code, you should understand what it means. Right, it is to first determine whether the current user is a visitor (not logged on), and then determine whether the controller of the current action is requested from SiteController, if yes, determine whether the login action in SiteController is requested. If not, redirect to the logon page. After testing, there is no problem at all. If you have special requirements, such as filtering multiple controllers and multiple actions, you can write an array and then traverse it.
In addition, your login page may not be the default one when yii was created. We recommend that you reload the CWebUser and change the loginUrl in the CWebUser.
Original article address: [original] Yii login verification in shanzhai mode. Thank you for sharing it with the original author.