2010-12-15 52 views
0

我試圖在Kohana 3(Orm Model)中添加驗證消息。Kohana 3:ORM驗證消息

類/模型/ 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.' 
    ) 
); 

?> 

輸出:

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

我沒有得到任何驗證消息,就這輸出以上... 任何ideia?謝謝。

回答

2

不帶任何參數調用->errors()意味着您需要錯誤原件而不是錯誤翻譯。結果將包含字段名稱及其錯誤描述(規則/回調名稱+應用的參數)。在您的示例中,您在responsavelemail字段中有not_empty規則(沒有參數)。

Btw,->errors('')->errors('validate')是同義詞。