Book Image

CakePHP Application Development

By : Ahsanul Bari, Anupom Syam
Book Image

CakePHP Application Development

By: Ahsanul Bari, Anupom Syam

Overview of this book

<p>Cake is a rapid development framework for PHP that uses well-known design patterns and provides a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss of flexibility. It means you can code faster, your code is better, and it makes writing Web 2.0-style apps a snap.<br /><br />This book offers step-by-step instructions to learn the CakePHP framework and to quickly develop and deploy web-based applications. It introduces the MVC pattern and coding styles using practical examples. It takes the developer through setting up a CakePHP development and deployment environment, and develops an example application to illustrate all of the techniques you need to write a complete, non-trivial application in PHP. It aims to assist PHP programmers to rapidly develop and deploy well-crafted and robust web-based applications with CakePHP.</p>
Table of Contents (18 chapters)
CakePHP Application Development
Credits
About the Authors
About the Reviewer
Preface
Index

Editing a Task


Now that we can add tasks to CakeTooDoo, the next thing that we will be doing is to have the ability to edit tasks. This is necessary because the users should be able to tick on a task when it has been completed. Also, if the users are not happy with the title of the task, they can change it. To have these features in CakeTooDoo, we will need to add another action to our Tasks Controller and also add a view for this action.

Time for Action: Creating the Edit Task Form

  1. Open the file tasks_controller.php and add a new action named edit as shown in the following code:

    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 saved');
    $this->redirect(array('action'=>'index'), null, true...