【发布时间】:2012-03-20 15:30:37
【问题描述】:
我被困住了。假设我有 string1 和 string 2(在同一模型中),其中 string1 有 7 位数字,而 string2 有 2 位数字。 然后我想将它们匹配在一起,其中 2 个 string1 的开头数字必须与 string2 相同。我在模型中尝试了这段代码>>
public function CekDigit($attribute,$params)
{
$attribute=substr($this->string1,0,-7);
$params=$this->string2;
if($this->$attribute==$params['subject'])
{
$this->addError(‘Error’, $params['message']);
return false;
}
}
在规则中,我放了这段代码>>
<?php
array('string1','cekdigit','message'=>'the code is unmatched','subject'),
?>
在我编写完该代码后,我尝试用 23xxxxxxx 填充 $string1 但我收到一个错误,即 CException : Property model.23 is not defined。有人可以帮我吗?非常感谢
【问题讨论】:
-
你能在 CekDigit() 中打印 $_POST 并复制粘贴结果吗?
-
我不认为你知道那里发生了什么......请仔细阅读 - yiiframework.com/wiki/168/create-your-own-validation-rule
-
看起来您在某个阶段将
$string1称为$$string1。此外,看起来您将$params设置为字符串($params=$this->string2),但随后您尝试与数组值进行比较($params['subject'])