The official Kohana form Validation tutorial is a bit rough. I have been reading it for half a day. This tutorial is a serialization tutorial, data or the previous data structure (KohanaORM) Step 1: In application/model/
The official Kohana form Validation tutorial is a bit rough. I have been reading it for half a day. This tutorial is a serialization tutorial, data or the data structure (Kohana ORM) described above)
Step 1: write verification rules in application/model/article. php:
// Verification rule public function rules () {return array ('CID' => array ('not _ empty ')), 'title' => array ('not _ empty'),), 'content' => array ('not _ empty '), array ('min _ length', array (': value', 4), array ('max _ length', array (': value ', 40 )),),);}
Step 2: write the verification prompt information in application/messages/models/article. php (create a directory without it)
*/Return array ('CID' => array ('not _ empty' => 'Article category cannot be blank '), 'title' => array ('not _ empty' => 'Article title cannot be blank '), 'content' => array ('not _ empty' => 'Article content cannot be blank ', 'min _ length' =>' content must be at least 4 characters ', 'max _ length' => 'content cannot exceed 40 characters '));
Step 3: compile the foreground html file: application/views/welcome/index. php
PHP dot-http://www.phpddt.com
Step 4: compile the Controller file application/controller/welcome. php:
find_all(); $this->template->category = $category; if($_POST) { $artile = ORM::factory('article')->values($_POST); $vali = Validation::factory($_POST, '_external', array()); try{ $artile->save($vali); } catch (ORM_Validation_Exception $e) { $this->template->errors = $e->errors('models'); } } }}
If the verification rule is not met, an error is prompted, such: