Re: beforeSave() is not called by save()
The debug is set to 2, so that sql queries are printed by default..
I also added a debug() message in the first line of beforeSave(), but
nothing is done...
Check out the code:
function beforeSave() {
debug("Hello World");
return true;
if (!empty($this->data)) {
$this->data['Content']['title'] = 'modified by beforeSave...';
}
return true;
}
It seems like cakephp, doesn't call beforeSave() at all and I cannot
figure this
out..
On Oct 16, 10:57 pm, John Andersen <j.andersen...@gmail.com> wrote:
> Turn on debug and place some debug statements in each function to see
> whether they are called in the sequence you expects. When done, tell
> us what you found out! :)
> Enjoy,
> John
>
> On Oct 16, 10:23 pm, Cris Sawfish <cris.sawf...@gmail.com> wrote:
>
> > Hi to all,
> > I have created the following (simple) Model.
>
> > <?php
>
> > class Content extends AppModel {
> > var $name = 'Content';
> > var $belongsTo = array(
> > 'Section' => array(
> > 'className' => 'Section',
> > 'foreignKey' => 'section_id'
> > )
> > );
>
> > };
>
> > function beforeSave() {
> > if (!empty($this->data)) {
> > $this->data['Content']['title'] = 'modified by beforeSave...';
> > }
> > return true;
>
> > }
> > ?>
>
> > I overloaded the beforeSave() method, which simply replaces the
> > current title with "modified by beforeSave...";
>
> > I also created an add() method in the ContentsController, to save form-
> > data. The method is as follows
>
> > function admin_add() {
> > if (!empty($this->data)) {
> > $sid = $this->data['Content']['section_id'];
> > $cont = $this->Content->find('all', array('conditions' => array
> > ('Content.section_id' => $sid)));
> > $this->Content->create();
> > if ($this->Content->save($this->data))
> > $this->flash('Content Saved!', 'index');
> > }
> > }
>
> > The save() method should normally call beforeSave(), (at least as
> > indicated by cakephp documentantion), but in my version of cakephp
> > (1.2.5 stable) it isn't.
> > I used to "embed" all the code into add() method, manually but this is
> > not the case for me right now.
>
> > Does anyone have any idea for this problem?
>
> > Thanx in advance
> > Christos
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home