Recently in the YII2.0 project, which needs to implement a function: No login can not access some of the pages, that is, visitor identity access restrictions. After half a day of information, finally found the answer. The workaround is as follows:
In access, access means that there is a configuration item ' only ' =>[' login ', ' about '] what does that mean, meaning it only works in login, about two action, that is, when the action
is login, about, will enter the rules to do next verification.
But what do we want to do except login, registration, and no other action is allowed to access? There are other configurations, we change only to except, what meaning, is to remove what outside of meaning, is
says it works for an action other than login and signup. Next, in rules=>[[' action ' =>[' login ', ' signup '], ' Allow ' =>true, ' roles ' =>['? ']] , the rules is the rule, here you can write.
Multiple, actions are the rules for which Action,allow refers to whether to allow access, the ' Roles ' field is critical, which is allowed to access the role. which Represents a visitor, @ represents a logged-on user.
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 '],
],
]
;
}