[英]Validate optional fields using Kohana 3.2 ORM
What is the simplest (cleaner) way to validate optional fields using Kohana 3.2 ORM? 使用Kohana 3.2 ORM验证可选字段的最简单(更简洁)方法是什么?
Well, maybe (:P) I've forgot the differences between mandatory fields and optional fields: 好吧,也许(:P)我忘记了必填字段和可选字段之间的区别:
'city' => array(
array('not_empty'),
array('min_length', array(':value', 3)),
array('max_length', array(':value', 255)),
),
'longitude' => array(
array('is_coordinate'),
)
The second one, the optional field 'longitude' is only triggered if has something that is not accepted by Valid::is_coordinate. 第二个,可选字段'经度'只有在Valid :: is_coordinate不接受的情况下才会被触发。
The first one, the mandatory field, is controlled by 'not_empty', or something with similar behavior. 第一个是必填字段,由'not_empty'或具有类似行为的东西控制。
About the filter, ORM filters are processed before the rules, so something like this is enough: 关于过滤器,ORM过滤器在规则之前处理,所以这样就足够了:
public function filters() {
return array(
'longitude' => array(array('trim'))
);
}
I'm tested myself right now, and is working nicely. 我现在正在测试自己,并且工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.