Class Sitecontroller extends Controller
{
/**
* @inheritdoc
*/
Public Function Behaviors ()
{
return [
' Access ' = [
' Class ' = Accesscontrol::classname (),
' Rules ' = [
[
' Actions ' = [' signup ', ' login '],
' Allow ' = true,
' Roles ' = ['? '],
],
[
' Actions ' = [' logout ', ' Index '],
' Allow ' = true,
' Roles ' = [' @ '],
],
],
],
' Verbs ' = [
' Class ' = Verbfilter::classname (),
' Actions ' = [
' Logout ' = [' post '],
],
],
];
}
}
? Represents a page that all visitors can see and use, and @ represents a page that can be accessed by authenticated users
If
Public Function Behaviors ()
{
return [
' Access ' = [
' Class ' = Accesscontrol::classname (),
' Only ' = ' index ',
' Rules ' = [
[
' Actions ' = [' signup ', ' login '],
' Allow ' = true,
' Roles ' = ['? '],
],
[
' Actions ' = [' logout ', ' Index '],
' Allow ' = true,
' Roles ' = [' @ '],
],
],
],
' Verbs ' = [
' Class ' = Verbfilter::classname (),
' Actions ' = [
' Logout ' = [' post '],
],
],
];
} Plus only, means that the method in the controller can only be used on the index page and no other pages will be accessible.
YII2 access Control