2010-12-15 17 views
0

私はKohana 3(Orm Model)で検証メッセージを追加しようとしています。私は、任意の検証メッセージを取得しないKohana 3:ORM検証メッセージ

Array ([responsavel] => Array ([0] => not_empty [1] => Array ()) [email] => Array ([0] => not_empty [1] => Array ())) 

、ちょうどこの:

クラス/モデル/ cliente.php

<?php defined('SYSPATH') or die('No direct script access.'); 

class Model_Cliente extends ORM { 
protected $_table_name = 'clientes'; 
protected $_primary_key = 'id'; 
protected $_has_one = array('loja' => array()); 
protected $_rules = array(
    'responsavel' => array('not_empty' => array(), 'min_length' => array(3)), 
    'email' => array('not_empty' => array(), 'email' => array()), 
    'telefone' => array('regex' => array('/^(\(\d{2}\)|\d{2})[ -]?\d{4}[ -]?\d{4}$/')) 
); 
} 
?> 

メッセージ/ cliente.php

<?php defined('SYSPATH') or die('No direct script access.'); 

return array(
    'responsavel' => array(
     'not_empty' => 'O nome do responsável não pode ficar em branco.', 
     'min_length' => 'O nome do responsável deve conter 3 caracteres ou mais.' 
    ) 
); 

?> 

出力上に出力... 任意のイデア?ありがとうございました。

答えて

6

今日も同じ問題がありました。

解決策:validate() - > errors()の代わりにvalidate() - > errors( '')を使用します。

これはhttps://github.com/samsoir/core/tree/master/classes/kohanaのベータコアですが、3.08では同じかもしれません。

+0

ありがとうございます。問題が解決しました! – thom

2

->errors()をパラメータなしで呼び出すと、エラー変換の代わりにエラーオリジナルが必要です。結果にはフィールド名とそのエラーの説明(ルール/コールバック名+パラメーターが適用されます)が含まれます。あなたの例ではresponsavelemailフィールドにはnot_emptyのルール(argsなし)があります。

Btw、->errors('')および->errors('validate')は同義語である。