Kohana Validation: Correct Range Rule Syntax

When setting up validation for one of my models, I am having trouble getting the correct syntax for the range rule. It seems that each variation passes only the (first) minimum parameter, and not the (second) maximum.

/** * @var array Validation rules */ public function rules() { return array( 'title' => array( array('not_empty'), array('max_length', array(':value', 50)), ), 'time' => array( array('not_empty'), array('date'), ), 'date' => array( array('not_empty'), array('date'), ), 'limit' => array( array('digit'), array('range', array(':value', 1), array(':value', 255)), ), ); } 

I also tried array('range', array(':value', array(1, 255))) no avail.

Any suggestions?

+4
source share
2 answers

For the correct syntax for a range rule, 3 parameters are required, not 2. As you can see in the documentation: http://kohanaframework.org/3.2/guide/api/Valid#range

So the code should be like this:

 array('range', array(':value', 1, 255)), 
+13
source

And be careful, range: min; max [not [min; max], therefore limits are excluded .

array ('range', array (': value', 1, 255)) => [2; 254]

+3
source

Source: https://habr.com/ru/post/1443976/


All Articles