2010-12-15 53 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')是同义词。