CI3の設定ファイルに検証ルールを使用するときにコールバックをどこに配置するのかわかりません。ここに私のform_validation.phpがある:私は上記を実行するとCI3 /設定ファイルへの検証ルールとコールバックの使用
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'blog_post' => array(
array(
'field' => 'entry_name',
'label' => 'entry_name',
'rules' => 'min_length[8]|trim|required|max_length[255]'
),
array(
'field' => 'entry_body',
'label' => 'entry_body',
'rules' => 'trim|required|min_length[12]|callback_html_length_without_html'
),
),
);
function html_length_without_html(){
if (2 < 1)
{
$this->form_validation->set_message('html_length_without_html', 'The field can not be the word');
return FALSE;
} else {
return TRUE;
}
}
しかし、私は次のエラーを取得する:
私はコールバック "html_length_without_htmlを()" を配置んUnable to access an error message corresponding
to your field name entry_body.(html_length_without_html)
?
ユーザーガイドを読んでいると、その答えがわかります。 https://www.codeigniter.com/userguide3/libraries/form_validation.html#callbacks-your-own-validation-methods – TimBrownlaw
はい、それを読んで、明らかにそれを取得していません。 – user3264461
その機能は、実際の検証を実行しているコントローラで行われます。検証ルールを設定するためにフォーム検証設定を使用しているのと同じコントローラ。 – TimBrownlaw