set_rules(...) 行でカスタム ライブラリのメソッドを呼び出そうとしています。
ネイティブの Form_validation クラスを拡張するクラス (アプリケーション/ライブラリ内) を作成し、そこにカスタム メソッドを記述できると聞きました。
したがって、次のコードを含む /application/libraries/MY_Form_validation.php があります。
class MY_Form_validation extends CI_Form_validation {
public function __construct()
{
parent::__construct();
}
function test_my_method($str)
{
//echo "test"; exit;
if ( ! is_array($str))
{
return (trim($str) == '') ? FALSE : TRUE;
}
else
{
return ( ! empty($str));
}
}
}
そして、私が持っているコントローラの機能で;
...
public function login() {
$this->load->library('form_validation');
//echo ($this->form_validation->test_my_method(''))? "true":"false";
$this->form_validation->set_rules('username', 'Username', 'trim|test_my_method');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run())
{ echo "Success"; }
}
...
set_rules() 行で呼び出された場合、関数 ( test_my_method ) にアクセスできません。何が間違っている可能性がありますか?ありがとう。