yii2: Captcha not accessible in backend of Advanced template

I made the below post in yii framework forum.

http://www.yiiframework.com/forum/index.php/topic/60118-creating-links-from-backend-to-frontend-and-frontend-to-backend/

I am not getting captcha image displayed in my backend. In frontend, I did not find any problem.

The request from backend view is as

http://localhost/admin/?r=site%2Fcaptcha&v=54827ca3d44dc

But, the status for the request is shown as 301 moved permanently.

The controller, model and view is made similar to the generated code when installing yii for ‘site/contact’ page.

I do not know if it a framework issue, but in my limited knowledge I am not able to find a solution.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

To solve the problem simply add ‘captcha’ in /backend/controllers/StiteController::behaviors():

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

and add the following in its actions():

 public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

This code works for me (Yii 2.0.3, advanced template)