I am making a mini message board, and am want to update
Discussion.last_post every time a new Response is saved.  The call to
saveField is on line 7 of ResponsesControllerThis is what I have:

************
<?php
class ResponsesController extends AppController {

        function add() {
                if (!empty($this->data)) {
                        if ($this->Response->save($this->data)) {
                                
$this->Response->Discussion->saveField('Discussion.last_post', date
('Y-m-d H:i:s'));
                                $this->Session->setFlash('Your message has been 
saved');
                                $this->redirect(array('controller' => 
'discussions', 'action' =>
'view', $this->data['Response']['discussion_id']));
                        } else {
                                $this->Session->setFlash('Your message could 
not be saved');
                        }
                }
        }

}
?>

************
<?php
class Discussion extends AppModel {

        var $hasMany = array('Response');

        var $validate = array(
                'author' => 'notEmpty',
                'title' => 'notEmpty',
                'content' => 'notEmpty'
        );

        function beforeSave() {
                $this->data['Discussion']['last_post'] = date('Y-m-d H:i:s');
                return true;
        }

}
?>

************
<?php
class Response extends AppModel {

        var $belongsTo = array('Discussion');

        var $validate = array(
                'author' => 'notEmpty',
                'title' => 'notEmpty',
                'content' => 'notEmpty'
        );

}
?>

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

Reply via email to