First of all, I'm using the ko3.2.0 version.
Kohana verification, with the students are less understanding, because each function of the comments will give an example. The situation today is to verify the image upload, the Kohana example is this way.
Copy CodeThe code is as follows: $array->rule (' file ', ' Upload::type ', array (' jpg ', ' png ', ' gif '));
This itself is not a problem, but, in the actual application is always a bit inconvenient, for what, because to the back of the processing, not only to verify the upload of the image to verify the form of some fields.
In general, we would write this.
Copy CodeThe code is as follows:
$post = new Validation ($_post);
$file = new Validation ($_files);
This writing is not a problem, the verification of the case by example is OK. But I think 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 have to turn them into a large array first.
Copy CodeThe code is as follows:
$post = new Validation (Array_merge ($_post,$_files));//Don't understand the classmate, degrees Niang under Array_merge
The focus is on the show, folks. Everyone knows there is no difference between validating the field of form form and merging it, the key is how to write this image (or other upload).
Well, the time relationship directly on the code, you can take to direct use, of course, interested students can also try the rules.
Copy CodeThe code is 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 foreground form form input type= "file" that control name, the background is not found ID.
Again, I use the kohana3.2.0 version, the other version of the note to change the wording.