Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CCaptcha displaying no image yii

Tags:

captcha

yii

I have a user registration form, in which I am trying to display a Captcha image by using Yii widget CCaptcha, however my image link appears broken, Controller file:

public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0xFFFFFF,
            ),
        );
    } 

Model File:

public function rules()
 {
    return array( array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'insert'), 
);
}

And view file:

<?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 shown.
        <br/>Letters are not case-sensitive.</div>
        <?php echo $form->error($model,'verifyCode'); ?>
    </div>
    <?php endif; ?>

As a answer provided somewhere I also tried giving the access rules in my controller file as

public function accessRules()
{
    return array(
        array('allow',
         'actions' => array('captcha'), 
         'users' => array('*'),
         ),
    );
}

But nothing seems to be working.

like image 440
dibs_ab Avatar asked Aug 10 '12 04:08

dibs_ab


1 Answers

The problem was with the controller file,it should have been,

public function accessRules()
    {
        return array(
            array('allow', 
                'actions'=>array('create', 'captcha'),
                'users'=>array('*'),
            ),
    } 


whereas I had mentioned the action for captcha at the end, which I figured out is not allowed in Yii. All the allow actions for * should be together.

like image 195
dibs_ab Avatar answered Nov 19 '22 10:11

dibs_ab