Rapid Application Development with Open Source Software

Next: Creating a desktop sitemap with CakePHP UP: TOC

Here is a first draft for the controller action in order to add comments:

autoRender = false;
    
    if ($this->request->is('post') and !empty($this->request->data['Comment']['email'])) {

        $this->Session = $this->Components->load('Session');

        // check if the sid in the session is the same as entered in the form:
        if ($this->Session->read('sid') == $this->request->data['Comment']['sid']) {     

            if ($this->Comment->save($this->request->data,true, array('content','email','chapter_id'))) {

               // compose a redirect to the chapter where the comment was entered:
               $redirect = '/books/';
               if (!empty($this->request->data['Comment']['book_id'])) 
                   $redirect .= $this->request->data['Comment']['book_id'];
               else 
                   $redirect .= '1';
               $redirect .= '/a/';
               if (!empty($this->request->data['Comment']['chapter_id'])) 
                   $redirect .= $this->request->data['Comment']['chapter_id'];
               else 
                   $redirect .= '1';
               $this->redirect($redirect);
            }
        }
    }
}

}
?>

Next: Creating a desktop sitemap with CakePHP UP: TOC