[Original] Yii login verification in shanzhai Mode

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.