In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The purpose of this article is to share with you how to solve the rules and restrictions of Yii2 against tourists and users. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Recently, I am working on a project with Yii2.0, which needs to implement a function: you can't access some pages without login, that is, visitor access restrictions. After searching the information for a long time, I finally found the answer. The solution is as follows:
In access, access means to visit, and there is a configuration item:
'only'= > [' login','about']
What does this mean? it means that it only works in the two action of login and about, that is, when action is login or about, it will enter the rules for further verification.
But what if we don't allow access to action except login and registration? There are other configurations. We change only to except. What does it mean? what does it mean except what? that is to say, it works on action except login and signup. Next, in:
The copy code is as follows:
Rules= > [['action'= > [' login','signup'], 'allow'= > true,'roles'= > ['?]
Rules is the rule, and multiple entries can be written in it. Actions refers to which action,allow the rule refers to whether access is allowed or not. The field 'roles'' is the key, which is the role of allowing access. Among them? On behalf of tourists, @ represents users who have logged in.
Public function behaviors () {return ['access' = > [' class' = > AccessControl::className (), 'except' = > [' login','signup'], 'rules' = > [' actions' = > ['login','signup'],' allow' = > true, 'roles' = > ['?], 'verbs' = > [' class' = > VerbFilter::className () 'actions' = > [' logout' = > ['post'],],] } the above is how to solve the problem of Yii2's rules and restrictions against tourists and users. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.