Captcha Broken Image

Hi Everyone

I use a lot of times the default captcha with Yii, almost without problem

Today I try to show the captcha on a module but the captcha image is broken (no image appearing). The other components of captcha (links, error matching code etc) seem to work correctly

My code in module Controller is


  public function actions() {

        return array(

            'captcha' => array(

                'class' => 'CCaptchaAction',

                'backColor' => 0xFFFFFF,

            ),

        );

}

In module view


 <?php if (CCaptcha::checkRequirements()): ?>

        <div class="row">

            <?php echo $form->labelEx($model, 'verifyCode'); ?>

            <div>

                <?php $this->widget('CCaptcha'); ?>

                <?php echo $form->textField($model, 'verifyCode'); ?>

            </div>

            <div class="hint">Please enter the letters as they are shown in the image above.

                <br/>Letters are not case-sensitive.</div>

            <?php echo $form->error($model, 'verifyCode'); ?>

        </div>

    <?php endif; ?>

And in model


  

public $verifyCode;

   ....

    public function rules() {

        return array(

            ....

            ....

            array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements()),

        );

}

The Same code with Controller/action/model/view as we all know

Why I have this problem?

Thanks

Ok, I found the problem

I had assign accessRules permissions for other actions

But I missed to do that for captcha … is an action itself!

So I had to add the captcha action like that


 public function accessRules() {

        return array(

            array('allow',

                'actions' => array('index', ... ... ,'captcha'),

                'users' => array('@'),

            ),

            array('deny', // deny all users

                'users' => array('*'),

            ),

        );

    }

Now all work fine!

Thanks for your time :)

Check the source code to see if an image tag has been rendered. If so, post the URL that’s been generated. That might help to determine the problem.

Edit: Sorted :lol:

Check out the first answer: http://stackoverflow.com/questions/11895376/ccaptcha-displaying-no-image-yii

Matt

Same thing: http://shanideveloper.blogspot.mx/2012/01/yii-ccaptcha-captcha-image-doesnt-show.html

Thanks a lot @Keith and @waterloommat!

Keith the image tag was exist ( So that I said broken image :) )

Waterloommat your links describe and solve my problem on the last step (accessRules())

Thanks both of you for your time :)