2013-05-18 101 views
0

我Yii中我的工作,我只是一个初学者,并尽我所能去学习框架,这里是我被困在其中:Yii的验证码错误

我创建了一个用户模型和去所需表格有了它,我想实现的验证码为它:

这是在用户模式我的验证规则:

$public verifyCode 

public function rules() 
    { 
     // NOTE: you should only define rules for those attributes that 
     // will receive user inputs. 
     return array(
      array('username, password, email', 'required'), 
      array('username','unique'), 
      array('email','email'), 
      array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()), 
      array('username, password', 'length', 'max'=>45), 
      array('email', 'length', 'max'=>100), 
      array('active', 'length', 'max'=>1), 
      array('created_on, updated_on', 'safe'), 
      // The following rule is used by search(). 
      // Please remove those attributes that should not be searched. 
      array('id, username, password, email, created_on, updated_on, active', 'safe', 'on'=>'search'), 
     ); 
    } 

这是我被覆盖的动作()在我的UserController中:

public function actions(){ 
     return array(
     'captcha'=>array(
      'class' => 'CCaptchaAction', 
      ) 
      ); 
    } 

这是我的看法文件:

<?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; ?> 

据我,我认为我正确但是所做的一切,是没有得到生成的验证码图像。哦,是的GD库已安装,如果我导航到网站/联系人,那么验证码生成罚款。

我似乎不明白,我在哪里弄错了。

这是我看到的东西:

enter image description here

的形式似乎不过是工作的罚款,我不能看到的验证码图像。

任何帮助,将不胜感激。

问候,

+2

有可能是访问权限到'CCaptchaAction'问题。你看过[这个解决方案](http://stackoverflow.com/a/11971926/506695)? – Ezze

+0

同时检查你是否在php中有'gd'库。尝试直接获取图像,并查看是否有任何错误,将图像下载到您的电脑并检查它的内容,也可能有一些提示。 – 2013-05-19 11:46:16

+0

gd是好的,因为'CCapcha :: checkRequirements()'返回true – rzelek

回答

1

我得到了答案,那是因为在控制器中定义的访问规则,我不得不修改控制器AccessControl的,像这样:

public function accessRules() 
    { 
     return array(
      array('allow', // allow all users to perform 'index' and 'view' actions 
       'actions'=>array('index','view','captcha'), 
       'users'=>array('*'), 
      ), 
      array('allow', // allow authenticated user to perform every action 
       'actions'=>array('create','update','admin','delete'), 
       'users'=>array('@'), 
      ), 

      array('deny', // deny all users 
       'users'=>array('*'), 
      ), 
     ); 
    }