[英]How does the CodeIgniter DataMapper ORM know which set of validation rules to apply?
[英]CodeIgniter 2, DataMapper Validation Rules
我正在將CodeIgniter 2與DataMapper ORM一起使用 。 對於用戶,我有confirm_password
和confirm_email
字段(以及其他字段),它們都不是數據庫中的字段(表users
沒有這些字段),但是可以在注冊表單上顯示這些字段:
我也有后端,這兩個字段( confirm_password
和confirm_email
)在表單中不存在。
public $validation = array(
'first_name' => array(
'label' => 'lang:common_first_name',
'rules' => array('required', 'trim')
),
'last_name' => array(
'label' => 'lang:common_last_name',
'rules' => array('trim')
),
'email' => array(
'label' => 'lang:common_email',
'rules' => array('required', 'trim', 'unique', 'valid_email')
),
'confirm_email' => array(
'label' => 'lang:common_confirm_email',
'rules' => array('matches' => 'email')
),
'password' => array(
'label' => 'lang:common_password',
'rules' => array('required', 'min_length' => 6, 'encrypt')
),
'confirm_password' => array(
'label' => 'lang:common_confirm_password',
'rules' => array('matches' => 'password')
)
);
如果我不作confirm_email
或confirm_email
必填字段,驗證不會觸發比賽規則。 如果我將它們設置為必填項 ,那么不具有這些字段的后端將觸發confirm_email
和confirm_password
,但不是。
$validation
數組中刪除confirm_email
索引)是一個好主意嗎? 我感激任何想法。 謝謝
您是否具有最新版本的ORM Mapper,根據文檔可以添加非數據庫字段。
http://stensi.com/datamapper/pages/validation.html
另外,您現在可以為非數據庫表字段添加驗證規則,例如“確認電子郵件地址”或“確認密碼”。 例如:
並且您不需要確認字段的必需規則-因為它們指示在DB中需要歸檔,因此出現DB錯誤),- match屬性將對匹配字段進行所需的驗證(例如,如果它不匹配)換句話說,您只需要在'email'字段中輸入必填項,如果歸檔的內容不匹配,confirmation_email將引發錯誤。 在空白字段中,您確實需要顯示電子郵件是必需的。
最后-您可以刪除索引,但是一般來說並不是一個好主意。 如果上述方法失敗,我將改為-在控制器中添加表單驗證規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.