4
比方說,我有一個ActiveRecord具有以下驗證規則:爲Yii的驗證規則外鍵
public function rules() {
return array(
array('model', 'required'),
// ....
array('model', 'exist',
'allowEmpty' => false,
'attributeName' => 'id',
'className' => 'Model',
'message' => 'The specified model does not exist.'
)
);
}
的第一條規則迫使model
場不爲空,第二個檢查它有一個一致的值( model
是外鍵)。
如果我試圖驗證一個表格,我留下空的字段model
我得到2個錯誤,一個用於第一個規則,一個用於第二個規則。
我想收到只有「不能爲空」的錯誤信息。
當第一條規則不滿意時,有沒有辦法停止驗證?
太棒了!這是我需要的。謝謝! – Andrea 2012-08-17 16:22:35
歡迎你,隨時樂意幫忙 – 2012-08-17 16:25:03