Hi, i'm new and trying  to learn how all these work, i'm following in
a tutorial the steps for a to-do list, but i cannot make my data
validates (the "title") when add or edit a new task and i don't know
what i'm doing wrong.. currently i'm using 1.2 RC4 and previously RC3
and didn't work either.. any help would be appreciated. Sorry for my
bad english. Thanks in advance.


////////////////////////////////
// Model
////////////////////////////////
<?php tasks.php
class Task extends AppModel {
        var $name = 'Task';
        var $validate = array(
                'title' => array(
                        'rule' => 'notEmpty',
                        'message' => 'title cannot be left empty.'
                 )
        );
}
?>

////////////////////////////////
// Controller tasks_controller.php
////////////////////////////////
<?php
class TasksController extends AppController {
        var $name = 'Tasks';
        var $helpers = array('Html','Form');
        function index() {
                $this->set('tasks', $this->Task->find('all'));
        }
        function add() {
                if (!empty($this->data)) {
                        $this->Task->create();
                        if ($this->Task->save($this->data)) {
                                $this->Session->setFlash('The Task has been 
saved');
                                $this->redirect(array('action'=>'index'), null, 
true);
                        } else {
                                $this->Session->setFlash('Task not saved. Try 
again.');
                        }
                }
        }
        function edit($id = null) {
                if (!$id) {
                        $this->Session->setFlash('Invalid Task');
                        $this->redirect(array('action'=>'index'), null, true);
                }
                if (empty($this->data)) {
                        $this->data = $this->Task->find(array('id' => $id));
                } else {
                        if ($this->Task->save($this->data)) {
                                $this->Session->setFlash('The Task has been 
savd');
                                $this->redirect(array('action'=>'index'), null, 
true);
                        } else {
                                $this->Session->setFlash('The Task could not be 
saved. Please, try
again.');
                        }
                }
        }
        function delete($id = null) {
                if (!$id) {
                        $this->Session->setFlash('Invalid id for task');
                        $this->redirect(array('action'=>'index'), null, true);
                }
                if ($this->Task->del($id)) {
                        $this->Session->setFlash('Task #'.$id.' deleted');
                        $this->redirect(array('action'=>'index'), null, true);
                }
        }
}
?>
////////////////////////////////
// View add.ctp
////////////////////////////////
<?php echo $form->create('Task');?>
        <fieldset>
                <legend>Add New Task</legend>
                <?php
                        echo $form->input('title');
                        echo $form->input('done');
                ?>
        </fieldset>
<?php echo $form->end('Add Task');?>
<?php echo $html->link('List All Tasks', array('action'=>'index'));?>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to