First of all, I'm using the ko3.2.0 version.
Kohana's verification, the use of the students are less understand points, because each function of the annotation will give an example. Today, the situation is to verify the image upload, kohana example is the case.
Copy Code code as follows:
$array->rule (' file ', ' Upload::type ', array (' jpg ', ' png ', ' gif '));
This itself is not a problem, but it is always a bit inconvenient in the actual application, why, because upload to the back of the processing, not only to verify the upload of the picture and to verify the form of some fields.
We usually write that.
Copy Code code as follows:
$post = new Validation ($_post);
$file = new Validation ($_files);
This is not a problem to write, the verification of the time by the example to write OK. But feel new2 times a bit strange, and we also know that $_post and $_files are arrays, can one test it? That's for sure, of course, we'll have to turn them into a large array. It's OK to write this.
Copy Code code as follows:
$post = new Validation (Array_merge ($_post,$_files)); The classmate who does not understand, degrees Niang under Array_merge
Focus on the show. Verify that the field of the form form is not different from the one before the merge, and the key is how to write this image (or upload).
Well, the time relationship directly on the code, we can take to direct use, of course, interested students can also try rules.
Copy Code code as follows:
$post->rule (' img ', ' not_empty ')
->rule (' img ', ' Upload::type ', Array (': Value ', array (' jpg ', ' png ', ' gif '))
->rule (' img ', ' upload::size ', Array (': Value ', ' 1M '));
Ps:img is the name of the control named "File" in the form of the foreground form, and the ID is not found in the background.
Again, I use the kohana3.2.0 version, the other version of attention to modify the wording.