简体   繁体   中英

Yii2 Advanced Template: Adding stand-alone web pages

I added help.php under backend/views/site and I declare a function under SiteController.php to be able to recognize the link

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['login', 'error'],
                    'allow' => true,
                ],
                [
                    'actions' => ['logout', 'index'],
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'logout' => ['post'],
            ],
        ],
    ];
}

public function actionHelp()
{
    return $this->render('help');
}

The link is now accessible but it gives me an error Forbidden(#403) and it says "You are not allowed to perform this action."

Now, I would like to ask if how will I be able to view the web pages that I've created. Thanks in advance.

The problem is related with AccessControl filter.

You can add help action to the this list of allowed actions for example like this:

[
    'actions' => ['login', 'error', 'help'],
    'allow' => true,
],

You can read more and check how access rules are applied in according documentation section .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM