Captcha image: error

Hi guys,

If I use original main-local.php I see captcha image in site/contact, if I use my extended main-local.php, I won’t see captcha image! As I used to experience, I have to define a rule in urlManger.Any ideas,how to define this rule? Original main-local:

<?php

Original main-local:




<?php

return [

    'components' => [

        'db' => [

            'class' => 'yii\db\Connection',

            'dsn' => 'mysql:host=localhost;dbname=yii2advanced',

            'username' => 'root',

            'password' => '',

            'charset' => 'utf8',

        ],

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            'viewPath' => '@common/mail',

            // send all mails to a file by default. You have to set

            // 'useFileTransport' to false and configure a transport

            // for the mailer to send real emails.

            'useFileTransport' => true,

        ],

    ],

];



Extended main-local:




<?php


return [

    'aliases' =>

    [

        '@uploadedfilesdir' => '@app/mails'

    ],

    'bootstrap' => ['debug'],

    'modules' => [

        'debug' => [

            'class' => 'yii\debug\Module',

        ]

    ],

    'components' => [

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

        ],

        'urlManager' => [

            'class' => 'yii\web\UrlManager',

            'enablePrettyUrl' => true,

            'showScriptName' => true,

            'enableStrictParsing' => true,

            'rules' => [

                '/' => 'site/index',

                'login' => 'site/login',

                'logout' => 'site/logout',

                'contact' => 'site/contact',

                'signup' => 'site/signup',

                'formular' => 'site/script',

                'reset' => 'site/request-password-reset',

                'bewerbungen' => 'bewerbungen/index',

                'country' => 'country/index',

                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>'

            ],

        ],

        'db' => [

            'class' => 'yii\db\Connection',

            'dsn' => 'mysql:host=localhost;dbname=yii2_widget',

            'username' => 'root',

            'password' => '',

            'charset' => 'utf8',

        ],],

];

?>



You have a couple of options but the easiest IMO is:

  1. Define Captcha url in form field



 <?= $form->field($model, 'verifyCode')->widget(\yii\captcha\Captcha::classname(), [

     'captchaAction' => '/captcha',

]) ?>



  1. Set rule in URL Manager since your using Strict Parsing. I’m going to set all your Site Controller in one rule (of course I’m lazy and didn’t do them all. I’ll let you add in the ones I left out but you’ll get the idea).



'rules' => [

      '<action:(login|logout|contact|captcha)>'  => 'site/<action>',

],



Of course you can add more actions to number 2 or get WAAAAY more complex than this.

Very nice. This helped me.

Thx a lot!