我刚刚意识到我的验证码不会显示图像,就好像它已经坏了。我确信在它运作良好之前,但我不知道发生了什么。
所以,我做的第一件事是更改为我使用Yii创建的原始编辑的模型,视图和控制器,但现在它也不起作用......
现在我有以下控制器(由Yii创建的原件):
<?php
class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
...
模特:
<?php
/**
* ContactForm class.
* ContactForm is the data structure for keeping
* contact form data. It is used by the 'contact' action of 'SiteController'.
*/
class ContactForm2 extends CFormModel
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, subject, body', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
...
和视图:
...
<?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; ?>
...
我认为我的问题可能与following link中报告的一样,所以我也使用了follow accessRules()
public function rules()
{
return array(
array('allow',
'actions' => array('captcha'),
'users' => array('*'),
),
);
}
和
public function rules()
{
return array(
array('allow',
'actions'=>array('create', 'captcha'),
'users'=>array('*'),
)
);
}
但两人都给了我错误:
“ContactForm2 tiene una regladevalidacióninválida.laregla se debe especificar attributos para ser validados y el nombre de su validador。”
拜托,有人可以帮帮我吗?为什么会这样?我读了很多关于这个主题的内容,但我找不到解决方案...