0
votes

When I logged in backend admin panel. It works fine but when I visit the link (eg: site.com/backend/web/site/manage-country) first time it won't show any error. If I visit the same link second time. It redirected to site.com and show this error.

exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in /home/kometonl/public_html/demo/vendor/yiisoft/yii2/filters/AccessControl.php:151

After clearing the cookies. I'll get the normal site back.

backend/controllers/SiteControllers.php

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

backend/config/main.php

'urlManager'=> [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
'site/manage-country' => 'site/managecountry',]
        ],
1
can u check out this array for behaviors return data - Nuriddin Rashidov
return [ 'access' => [ 'class' => AccessControl::className(), 'only' => ['index', 'logout', 'login', 'manageCountry'], 'rules' => [ [ 'allow' => true, 'roles' => ['@'], ], [ 'allow' => true, 'actions' => ['login'], 'roles' => ['?'], ], [ 'allow' => true, 'actions' => ['logout'], 'roles' => ['@'], ],],],]; - Nuriddin Rashidov
the code has no effect. when i logged in. it redirects to the index page. After I reached index page. Whatever I clicked it works but the second time or when i reload that page it won't work and it shows the above mentioned error. - Kartz

1 Answers

0
votes

Change Your Behaviour As

[
   'actions' => ['logout', 'index','managecountry'],
   'allow' => true,
   'roles' => ['@'],
                    ],

in SiteController

 public function actionManagecountry(){
        echo 'hi';
    }