Yii验证码验证检查不起作用

Yii验证码验证检查不起作用,yii,captcha,Yii,Captcha,这是我的模型: public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. if ($this->scenario == "insert") { return array( array('requisition

这是我的模型:

public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.

        if ($this->scenario == "insert") {
            return array(
                array('requisition_id, sync', 'numerical', 'integerOnly' => true),
                array('lastname, firstname, email, dob, phone, cv_path, experienceMonths, experienceYears, competencies, token', 'required', 'message' => "Câmpul este obligatoriu"),
                array('email', 'email', 'message' => "Emailul este invalid!"),
                array('dob', 'validateDob'),
                array('dayOfBirth, monthOfBirth, yearOfBirth', 'safe'),
                array('taleo_id, sync', 'required', 'on' => 'taleoUpdate'),
                array('verifyCode', 'on' => 'insert'),
                // The following rule is used by search().
                // Please remove those attributes that should not be searched.
            );
        } else if ($this->scenario == 'taleoUpdate') {
            return array(
                array('taleo_id, sync', 'required'),
                // The following rule is used by search().
                // Please remove those attributes that should not be searched.
            );
        }
        else if($this->scenario == 'notjobapply'){
            return array(
                array('lastname, firstname, email, phone, cv_path, requisition_id', 'required', 'message'=>'Câmpul este obligatoriu'),
                array('email', 'email', 'message' => "Emailul este invalid!"),
            );
        }


        return array(
            array('id, lastname, email, phone, dob, requisition_id, experienceMonths, experienceYears, sync, cv_path, created', 'safe', 'on' => 'search'),
            array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'captchaRequired'),
        );
    }

我的问题是它无法验证图像中的字母。我不知道为什么。我认为我的确认在规则中是不正确的。有什么线索吗

是的,您有很多场景,并对它们应用不同的规则

确保您当前运行的场景具有验证规则

我可以看到你用两种方式使用场景,一种是你使用的条件,我不完全确定它们是否有效,但也许它们确实有效

第二种是Yii方式,通过在每个规则声明的“on”属性中指定

我建议在此结构中从头开始重新编写所有规则:

return array(
    // scenarioA
    array('field1, field2', 'required', 'on' => 'scenarioA'),
    array('field1, field2', 'required', 'on' => 'scenarioA'),
    array('field1, field2', 'required', 'on' => 'scenarioA'),
    // scenarioB
    array('field3, field4', 'required', 'on' => 'scenarioB'),
    array('field3, field4', 'required', 'on' => 'scenarioB'),
    array('field3, field4', 'required', 'on' => 'scenarioB'),
    // scenarioC
    array('field5, field6', 'required', 'on' => 'scenarioC'),
    array('field5, field6', 'required', 'on' => 'scenarioC'),
    array('field5, field6', 'required', 'on' => 'scenarioC'),
);
或者,如果测试条件块的行为是否正确,则可以保留条件块解决方案,但在这种情况下,应该从块内的规则中删除“on”参数

因为这里举个例子:

if ($this->scenario == "insert") {
            return array(
                ...
                array('taleo_id, sync', 'required', 'on' => 'taleoUpdate'),
您将代码放在验证场景为“插入”的条件中,但再次指定“打开”,这将使该规则仅应用于“TaleOutdate”场景,因此没有意义

哦,至于验证码,正如你所看到的那样,只有当场景与你上面指定的场景不同时,你才能使用你的格式达到它的规则