このdocumentationに基づいて、2番目のパラメータをルールメソッドに渡す方法は?Codeigniterカスタム検証ルールに余分なパラメータを渡す
これは私のカスタムルール
public function email_exists($email, $exclude_id=NULL)
{
if ($exclude_id !== NULL) $this->db->where_not_in('id', $exclude_id);
$result = $this->db->select('id')->from('users')->where('email', $email)->get();
if ($result->num_rows() > 0) {
$this->form_validation->set_message('email_exists', '{field} has been used by other user.');
return FALSE;
} else {
return TRUE;
}
}
であり、これは私がemail_existsメソッドの2番目のパラメータを渡すことができますどのように
$rules = [
[
'field' => 'email',
'label' => 'Email',
'rules' => [
'required',
'trim',
'valid_email',
'xss_clean',
['email_exists', [$this->m_user, 'email_exists']]
]
]
];
$this->form_validation->set_rules($rules);
コントローラ
からそれを呼び出す方法ですか?これは$exclude_id
ためのフォームで隠しフィールドを作るよりも、機能していない場合
$this->form_validation->set_rules('uri', 'URI', 'callback_check_uri['.$this->input->post('id').']');
// Later:
function check_uri($field, $id){
// your callback code here
}
と直接のことを確認してください。
感謝を提供してくれてありがとうはskunkbadするが、私は任意のコントローラからそれを呼び出すことができるようにドキュメントに基づいて、私はモデルでルールを置きます。あなたの提案に従えば、ルールは現在のコントローラでのみ利用可能になります。 – milikpribumi