05.26
php
saved
dardosordi
Note
MVC example for a simple validation
MVC example for a simple validation
- MODEL:
- -----
- <?php
- class Post extends AppModel {
- var $name = 'Post';
- 'required' => true,
- 'allowEmpty' => false,
- 'message' => 'Please set a title'
- )
- );
- }
- ?>
- CONTROLLER:
- ----------
- <?php
- class PostsController extends AppController {
- var $name = 'Posts';
- function index() {
- $this->set('posts', $this->paginate());
- }
- function add() {
- if ($this->Post->save($this->data)) {
- $this->Session->setFlash('Post added.');
- }
- debug($this->Post->validationErrors);
- }
- }
- }
- ?>
- VIEW:
- -----
- <h2>Add Post</h2>
- $form->input('title'),
- $form->input('body'),
- $form->end('Add'); ?>
Parsed in 0.071 seconds, using GeSHi 1.0.7.14