Yii CAPTCHA url is broken

后端 未结 1 1933
臣服心动
臣服心动 2021-01-21 07:36

I want to create an AJAX-registration form on my Yii-project. So on every page I have a login-button, which shows a popup if the user isn\'t authorized. In that popup he can see

相关标签:
1条回答
  • 2021-01-21 08:22

    So, while I was waiting for help, I solved the problem by myself :) In my project i separated my controllers into the next hierarchy:

    /frontend
    /backend
    

    All controllers for common users are (of course) in Frontend section, including UserController and MainController.

    Yes, I wrote some configs to hide /frontend/ in URL's like this:

    '<c:\w+>/<a:\w+>' => 'frontend/<c>/<a>',
    

    And i was sure, that string in my CAPTCHA config ('captchaAction' => '/user/captcha') knows where to go (and it was almost so!), but NO!

    I should write FULL PATH to my controller and action like below:

    'captchaAction' => '/frontend/main/captcha',
    

    As I said in question, I placed my CAPTCHA action in UserController, but now you can see it is located in MainController (i deleted it from UserController)

    And I got an error:

    CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller. 
    

    So, to solve this, I just had to use a property captchaAction of CCaptchaValidator in my User MODEL! Code:

    array('code', 'captcha', 'captchaAction'=>'/frontend/main/captcha', 'allowEmpty'=>!Yii::app()->user->isGuest)
    

    So, now my AJAX Captcha validation works correctly where I want.

    Good luck with Yii's default CAPTCHA, dear community!

    0 讨论(0)
提交回复
热议问题