A
A
Alexey G2019-01-17 08:51:38
Yii
Alexey G, 2019-01-17 08:51:38

Why Yii2 Captcha doesn't see Action in module?

So. All actions take place on the Yii2 framework in the feedback module
Routing:

public $urlRules = [
        'prefix' => 'feedback',
        'routePrefix' => 'feedback',
        'rules' => [
            'send' => 'send',
            'captcha' => 'default/captcha',
        ],
    ];

Controller:
class DefaultController extends Controller
{
public function actions()
    {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                //'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }
}

Model
...
public function rules()
    {
...
 $rules[] = [$field, 'captcha', 'captchaAction'=>'/feedback/captcha'];
...
}
...

The form:
...
 echo $form->field($this, $field)->widget(Captcha::className([
                        'captchaAction' => '/feedback/captcha'
                    ]));
...

If you go to the
site.ru/feedback/captcha
page, then everything is OK - we will see a picture (captcha).
But when I go to the feedback form, I get an error:
Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message 'Invalid CAPTCHA action ID: /feedback/captcha'

I tried to write in the model like this:
$rules[] = [$field, 'captcha', 'captchaAction'=>'/feedback/default/captcha'];

In this case, the error does not occur, but the image address becomes:
/feedback/site/captcha?v=5c4016f819eec6.36931450 , where the site comes from is not clear, and, accordingly, the image is not there..

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question