我有一个用户注册表单,我试图通过使用Yii widget CCaptcha来显示Captcha图像,但是我的图像链接显示为已损坏,
控制器文件:
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}
模型文件:
public function rules()
{
return array( array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'insert'),
);
}
查看档案:
<?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; ?>
作为某处提供的答案,我也尝试在控制器文件中提供访问规则为
public function accessRules()
{
return array(
array('allow',
'actions' => array('captcha'),
'users' => array('*'),
),
);
}
但似乎没有任何效果。
答案 0 :(得分:8)
问题在于控制器文件,应该是,
public function accessRules()
{
return array(
array('allow',
'actions'=>array('create', 'captcha'),
'users'=>array('*'),
),
}
虽然我最后提到过验证码的动作,但我认为Yii不允许这样做。 *的所有允许操作应该在一起。
答案 1 :(得分:-1)
Yii captcha将创建一个png图像。对于损坏的图像链接的可能解释是缺少GD扩展或图像扩展,可以通过error.log
中存在以下文本来识别:
调用未定义的函数imagecreatetruecolor
有关详情和修正,请参阅"call to undefined function imagecreatetruecolor" error in PHP & pChart