Sha*_*man 4 validation model yii yii-validation
有谁知道如何在Yii模型中应用规则输入必须大于0值,没有任何自定义方法..
喜欢 :
public function rules()
{
return array(
....
....
array('SalePrice', 'required', "on"=>"sale"),
....
....
);
}
Run Code Online (Sandbox Code Playgroud)
非常感谢 ..
更简单的方法
array('SalePrice', 'numerical', 'min'=>1)
使用自定义验证器方法
array('SalePrice', 'greaterThanZero')
public function greaterThanZero($attribute,$params)
{
if ($this->$attribute<=0)
$this->addError($attribute, 'Saleprice has to be greater than 0');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19935 次 |
| 最近记录: |