zoukankan      html  css  js  c++  java
  • yii2 访问控制

    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'],
    ],
    ],
    ];
    }

    }

    ?表示所有访客都可以看见和使用的页面,@表示通过验证的用户可以访问的页面

    如果

    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'],
    ],
    ],
    ];
    }加上了only,则表示该控制器中的方法只能用于index页面,其他页面都不能访问。

  • 相关阅读:
    MySQL 通过多个示例学习索引
    git reset的用法
    git rebase的用法
    学习yii2.0——依赖注入
    学习yii2.0——行为
    学习yii2.0——事件
    学习yii2.0——数据验证
    让Apache和Nginx支持php-fpm模块
    安装python3
    使用php操作memcache
  • 原文地址:https://www.cnblogs.com/lyy-php/p/4761365.html
Copyright © 2011-2022 走看看