梦里花落0921
有几种类型的配置:1) 使用主要配置阻止对整个应用程序(ak 后端)的访问:// ../config/main.phpreturn [ // ... 'components' => [ // ... ], 'as access' => [ 'class' => yii\filters\AccessControl::class, 'except' => ['site/error', 'site/login', 'site/logout'], 'rules' => [ ['allow' => true, 'roles' => ['@']], ], ],];2)通过扩展抽象控制器类来阻止对特定控制器的访问use yii\filters\AccessControl;use yii\web\Controller;/** * AbstractSecured controller */abstract class AbstractSecuredController extends Controller{ /** * {@inheritdoc} */ public function behaviors() { return [ 'access' => [ 'class' => AccessControl::class, // ... // rules ] ]; }}现在你可以在你的控制器中扩展这个控制器use yii\helpers\ArrayHelper;/** * MyNonPublic controller */class MyNonPublicController extends AbstractSecuredController{ /** * {@inheritdoc} */ public function behaviors() { return ArrayHelper::merge( parent::behaviors(), [ // ... // controller specific behaviors // you can even rewrite access behavior config ] ); }}3)你也可以配置ACL