0
私はkohanaに深く潜入しています。特にhmvcのものとはるかに。 現時点では、自分のルールを検証インスタンスに追加する際に問題があります。個別のバリデーションルールと関数を追加する、kohana 3.0.8
検証がうまく実行され、私自身の関数が正しく呼び出されるとも思います。問題は、自分の検証機能のエラーメッセージが表示されないということです。
多分誰かが私が間違って何をしたか確認するために、コードの中に見ることができます。ありがとう!ここ
は、私は少しそれを短縮するためにいくつかのものを削除し、私のコードです:
class Controller_Bookmarks extends Controller_DefaultTemplate
{
public function action_create_bookmark()
{
$posts = new Model_Post();
if($_POST){
$post = new Validate($_POST,$_FILES);
//attaching rules
$post ->rule('bookmark_title', 'not_empty')
->rule('bookmark_image', 'Model_Post::email_change');
//add error for custom functionm
$post->error('bookmark_image', 'email_change');
if ($post->check())
{
echo 'yeah';
}else{
print_r($post->errors('validate'));
}
}else{
}
$this->template->content = View::factory('pages/create_bookmark');
}
}
私のモデル:
class Model_Post extends Kohana_Model
{
public function email_change($str)
{
return false;
}
}
(単なるテスト用)私のエラーメッセージ定義メッセージ/ Validate.phpと:
<?php defined('SYSPATH') or die('No direct script access.');<br />
return array(
'alpha' => ':field must contain only letters',
'alpha_dash' => ':field must contain only letters and dashes',
'alpha_numeric' => ':field must contain only letters and numbers',
'color' => ':field must be a color',
'credit_card' => ':field must be a credit card number',
'date' => ':field must be a date',
'decimal' => ':field must be a decimal with :param1 places',
'digit' => ':field must be a digit',
'email' => ':field must be a email address',
'email_domain' => ':field must contain a valid email domain',
'exact_length' => ':field must be exactly :param1 characters long',
'in_array' => ':field must be one of the available options',
'ip' => ':field must be an ip address',
'matches' => ':field must be the same as :param1',
'min_length' => ':field must be at least :param1 characters long',
'max_length' => ':field must be less than :param1 characters long',
'phone' => ':field must be a phone number',
'not_empty' => ':field rrrrrrrrrrrrrrrrrrrrr must not be empty',
'range' => ':field must be within the range of :param1 to :param2',
'regex' => ':field does not match the required format',
'url' => ':field must be a url',
'email_change' => ':field gdffddfgdfhgdfhdfhhdfhdfhdfhd',
);
thats、ありがとうございます。それは時々簡単にできる。 –