Re: beforeSave not working with saveMany?

2012-06-05 Thread Benjamin Allison
Hmm. In doing a saveMany, [this->alias] isn't defined.

saveMany uses a numerical index.

On Tuesday, 5 June 2012 18:06:47 UTC-4, stork wrote:
>
> $this->data[$this->alias]['foo'] = 'bar';
>
> or
>
> $this->set('foo', 'bar');

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: beforeSave not working with saveMany?

2012-06-05 Thread stork


public function beforeSave($options = array()) {
$this->set('foo', 'bar');
return parent::beforeSave($options);
}


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: beforeSave not working with saveMany?

2012-06-05 Thread stork
$this->data[$this->alias]['foo'] = 'bar';

or

$this->set('foo', 'bar');

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: beforeSave vs beforeValidate

2010-03-13 Thread j0n4s.h4rtm...@googlemail.com
It depends,

it depends on your use case. For instance if one may enter text into a
huge textfield, maybe richtext for instance, its better to sanitize
after READING it from the database, not upon writing (beforesave).

If you want to change things on the fly before validation its no
problem. For instance if you require first and last name, and both do
neither start nor end with whitespace, tab, linebreak but with some
other character and are at least 3 letters long, you can strip those
whitespaces (lets say with trim()) in beforeValidate. The result will
also be that on validation issues the result in the form will be
modified (while beforesave the modification is not visible to the user
at any chance).

There is no general rule where it is best to do do, beforeValidate,
beforeSave, afterRead

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: beforeSave vs beforeValidate

2010-03-12 Thread Dr. Loboto
The flow is beforeValidate -> validate -> beforeSave -> save

First beforeValidate() callback is to check data and make global
decision go further / this data cannot be validated/saved. If answer
is no save() immediately returns false.
If beforeValidate() was successful actual validation occurs. If it
fails save() returns false.
If validation sucseed, beforeSave() is called. Here you can as modify
data if you want some fields go to DB in other format that user
entered as make some additional validation. Again, you can return
false and abort save.
Only if beforeSave() was successful actual save takes place.

So callbacks named exactly as they behave.

On Mar 13, 4:04 am, "Dave"  wrote:
> Most tutorials or tips online refer to before Save () as a good before
> saving to clean data and what not but never have i seen anything on
> beforeValidate as beforeValidate seems to be better to use i would think.
> No?
>
> For example city has validation rules say min 5 characters if someone enters
> "b"  into the city field that meets the minimum 5 character yes then
> you beforeSave clean out the html so you left with "b" as the city name yet
> thats not 5 charaters you were wanting to ensure. so you save "b" as the
> city name
>
> Is it not best to say use beforeValidate to clean up your data make sure it
> meets validation if so then do your beforesave on that data?
>
> I was using beforeSave and noticed i could trick cake into thinking it was
> ok and could actually just put html tags into fields to meet min
> requirements, a-z-0-9 and actually save an entire form record and every
> field inthe db was completely blank because it said it was valid and the
> data that was safe to save was actually nothing yet i set up notempty =>
> true.
>
> Any thoughts?
>
> Dave

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: beforeSave vs beforeValidate

2009-12-03 Thread naidim
It appears that's it. Thank you.

"beforeSave: Called before each save operation, after validation.
Return a non-true result to halt the save."

On Dec 2, 9:38 am, "j0n4s.h4rtm...@googlemail.com"
 wrote:
> Check what those methods have to return, at least(maybe both) one of
> them (I "think" it was beforeSave) has to return true;
>
> On Dec 1, 10:46 pm, naidim  wrote:
>
> > Sorry, I meant to say the code is in the user MODEL not controller.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: beforeSave vs beforeValidate

2009-12-02 Thread j0n4s.h4rtm...@googlemail.com
Check what those methods have to return, at least(maybe both) one of
them (I "think" it was beforeSave) has to return true;

On Dec 1, 10:46 pm, naidim  wrote:
> Sorry, I meant to say the code is in the user MODEL not controller.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: beforeSave vs beforeValidate

2009-12-01 Thread naidim
Sorry, I meant to say the code is in the user MODEL not controller.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: beforeSave?

2009-11-19 Thread Dave
Thanks guys.

I dont know why I was adding it to the controller :( But it works as
it should.

Thanks for your time and patience.

Dave

On Nov 19, 4:27 am, David Roda  wrote:
> No problem,  I am not sure the OP has it in his model though
>
> On Thu, Nov 19, 2009 at 2:21 AM, jburns  wrote:
> > My apologies - I meant model but typed controller inadvertently.
>
> > On Nov 19, 7:18 am, David Roda  wrote:
> > > beforeSave is a model callback, not a controller call back.  It needs to
> > go
> > > into your model
>
> > > On Wed, Nov 18, 2009 at 11:06 PM, jburns  wrote:
> > > > Whenever I have used beforeSave in a controller (not sure if you are
> > > > using this in AppController?) I have called parent::beforeSave();
> > > > first. Really don't know if that will make a difference or not.
>
> > > > On Nov 19, 4:02 am, Dave  wrote:
> > > > > Ok now I have
>
> > > > > function beforeSave()
> > > > >          {
>
> > > > >                 return false;
> > > > >          }
>
> > > > > so it should fail automatically but it still saves. There has to be
> > > > > something very wrong.
>
> > > > > Any one have any ideas what so ever? This makes no sense what so
> > ever.
>
> > > > > Dave
>
> > > > > On Nov 18, 9:05 pm, Dave  wrote:
>
> > > > > > I have :
>
> > > > > > function beforeSave()
> > > > > >       {
> > > > > >           App::import('Core', 'sanitize');
> > > > > >           $this->data = Sanitize::clean($this->data);
> > > > > >           return true;
> > > > > >       }
>
> > > > > > But no matter what I save nothing happens to the data.
>
> > > > > > Even tried adding this to the before save
>
> > > > > > function beforeSave()
> > > > > >       {
> > > > > >           App::import('Core', 'sanitize');
> > > > > >           $this->data = Sanitize::clean($this->data);
>
> > > > > >                 if(!empty($this->data))
> > > > > >                 {
> > > > > >                 $this->data['Award']['title'] = 'added from
> > > > beforeSave';
>
> > > > > >                 }
> > > > > >           return true;
> > > > > >       }
>
> > > > > > But still nothing.
>
> > > > > > Any ideas anyone?
>
> > > > > > On Nov 18, 2:40 am, Erik Nedwidek 
> > wrote:
>
> > > > > > > Dave,
>
> > > > > > > No need to call the beforeSave method as it is a callback.
>
> > > > > > > function beforeSave() {
> > > > > > >   App::import('Sanitize');
> > > > > > >   $this->data = Sanitize::clean($this->data);
>
> > > > > > >   return true;
>
> > > > > > > }
>
> > > > > > > That should be all you need to do. Throw a couple of $this->log()
> > > > statements
> > > > > > > in there to verify the method is being called by Cake if you're
> > not
> > > > sure.
>
> > > > > > > Erik Nedwidek
> > > > > > > Project Manager
> > > > > > > Lighthouse I.T. Consulting, Inc.
>
> > > > > > > On Tue, Nov 17, 2009 at 10:37 PM, Dave 
> > > > wrote:
> > > > > > > > Do you manually have to call beforeSave();
>
> > > > > > > > I have
> > > > > > > > function beforeSave()
> > > > > > > >  {
> > > > > > > >        $clean = new Sanitize();
> > > > > > > >        $this->data = $clean->clean($this->data);
> > > > > > > > return true;
>
> > > > > > > >  }
>
> > > > > > > > But it does nothing to the data.
>
> > > > > > > > What am I doing wrong?
>
> > > > > > > > Dave
>
> > > > > > > > --
>
> > > > > > > > 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=.
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "CakePHP" group.
> > > > To post to this group, send email to cake-...@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=.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-...@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=.
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread David Roda
No problem,  I am not sure the OP has it in his model though

On Thu, Nov 19, 2009 at 2:21 AM, jburns  wrote:

> My apologies - I meant model but typed controller inadvertently.
>
> On Nov 19, 7:18 am, David Roda  wrote:
> > beforeSave is a model callback, not a controller call back.  It needs to
> go
> > into your model
> >
> >
> >
> > On Wed, Nov 18, 2009 at 11:06 PM, jburns  wrote:
> > > Whenever I have used beforeSave in a controller (not sure if you are
> > > using this in AppController?) I have called parent::beforeSave();
> > > first. Really don't know if that will make a difference or not.
> >
> > > On Nov 19, 4:02 am, Dave  wrote:
> > > > Ok now I have
> >
> > > > function beforeSave()
> > > >  {
> >
> > > > return false;
> > > >  }
> >
> > > > so it should fail automatically but it still saves. There has to be
> > > > something very wrong.
> >
> > > > Any one have any ideas what so ever? This makes no sense what so
> ever.
> >
> > > > Dave
> >
> > > > On Nov 18, 9:05 pm, Dave  wrote:
> >
> > > > > I have :
> >
> > > > > function beforeSave()
> > > > >   {
> > > > >   App::import('Core', 'sanitize');
> > > > >   $this->data = Sanitize::clean($this->data);
> > > > >   return true;
> > > > >   }
> >
> > > > > But no matter what I save nothing happens to the data.
> >
> > > > > Even tried adding this to the before save
> >
> > > > > function beforeSave()
> > > > >   {
> > > > >   App::import('Core', 'sanitize');
> > > > >   $this->data = Sanitize::clean($this->data);
> >
> > > > > if(!empty($this->data))
> > > > > {
> > > > > $this->data['Award']['title'] = 'added from
> > > beforeSave';
> >
> > > > > }
> > > > >   return true;
> > > > >   }
> >
> > > > > But still nothing.
> >
> > > > > Any ideas anyone?
> >
> > > > > On Nov 18, 2:40 am, Erik Nedwidek 
> wrote:
> >
> > > > > > Dave,
> >
> > > > > > No need to call the beforeSave method as it is a callback.
> >
> > > > > > function beforeSave() {
> > > > > >   App::import('Sanitize');
> > > > > >   $this->data = Sanitize::clean($this->data);
> >
> > > > > >   return true;
> >
> > > > > > }
> >
> > > > > > That should be all you need to do. Throw a couple of $this->log()
> > > statements
> > > > > > in there to verify the method is being called by Cake if you're
> not
> > > sure.
> >
> > > > > > Erik Nedwidek
> > > > > > Project Manager
> > > > > > Lighthouse I.T. Consulting, Inc.
> >
> > > > > > On Tue, Nov 17, 2009 at 10:37 PM, Dave  >
> > > wrote:
> > > > > > > Do you manually have to call beforeSave();
> >
> > > > > > > I have
> > > > > > > function beforeSave()
> > > > > > >  {
> > > > > > >$clean = new Sanitize();
> > > > > > >$this->data = $clean->clean($this->data);
> > > > > > > return true;
> >
> > > > > > >  }
> >
> > > > > > > But it does nothing to the data.
> >
> > > > > > > What am I doing wrong?
> >
> > > > > > > Dave
> >
> > > > > > > --
> >
> > > > > > > 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=.
> >
> > > --
> >
> > > You received this message because you are subscribed to the Google
> Groups
> > > "CakePHP" group.
> > > To post to this group, send email to cake-...@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=.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread jburns
My apologies - I meant model but typed controller inadvertently.

On Nov 19, 7:18 am, David Roda  wrote:
> beforeSave is a model callback, not a controller call back.  It needs to go
> into your model
>
>
>
> On Wed, Nov 18, 2009 at 11:06 PM, jburns  wrote:
> > Whenever I have used beforeSave in a controller (not sure if you are
> > using this in AppController?) I have called parent::beforeSave();
> > first. Really don't know if that will make a difference or not.
>
> > On Nov 19, 4:02 am, Dave  wrote:
> > > Ok now I have
>
> > > function beforeSave()
> > >          {
>
> > >                 return false;
> > >          }
>
> > > so it should fail automatically but it still saves. There has to be
> > > something very wrong.
>
> > > Any one have any ideas what so ever? This makes no sense what so ever.
>
> > > Dave
>
> > > On Nov 18, 9:05 pm, Dave  wrote:
>
> > > > I have :
>
> > > > function beforeSave()
> > > >       {
> > > >           App::import('Core', 'sanitize');
> > > >           $this->data = Sanitize::clean($this->data);
> > > >           return true;
> > > >       }
>
> > > > But no matter what I save nothing happens to the data.
>
> > > > Even tried adding this to the before save
>
> > > > function beforeSave()
> > > >       {
> > > >           App::import('Core', 'sanitize');
> > > >           $this->data = Sanitize::clean($this->data);
>
> > > >                 if(!empty($this->data))
> > > >                 {
> > > >                 $this->data['Award']['title'] = 'added from
> > beforeSave';
>
> > > >                 }
> > > >           return true;
> > > >       }
>
> > > > But still nothing.
>
> > > > Any ideas anyone?
>
> > > > On Nov 18, 2:40 am, Erik Nedwidek  wrote:
>
> > > > > Dave,
>
> > > > > No need to call the beforeSave method as it is a callback.
>
> > > > > function beforeSave() {
> > > > >   App::import('Sanitize');
> > > > >   $this->data = Sanitize::clean($this->data);
>
> > > > >   return true;
>
> > > > > }
>
> > > > > That should be all you need to do. Throw a couple of $this->log()
> > statements
> > > > > in there to verify the method is being called by Cake if you're not
> > sure.
>
> > > > > Erik Nedwidek
> > > > > Project Manager
> > > > > Lighthouse I.T. Consulting, Inc.
>
> > > > > On Tue, Nov 17, 2009 at 10:37 PM, Dave 
> > wrote:
> > > > > > Do you manually have to call beforeSave();
>
> > > > > > I have
> > > > > > function beforeSave()
> > > > > >  {
> > > > > >        $clean = new Sanitize();
> > > > > >        $this->data = $clean->clean($this->data);
> > > > > > return true;
>
> > > > > >  }
>
> > > > > > But it does nothing to the data.
>
> > > > > > What am I doing wrong?
>
> > > > > > Dave
>
> > > > > > --
>
> > > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > > "CakePHP" group.
> > > > > > To post to this group, send email to cake-...@googlegroups.com.
> > > > > > To unsubscribe from this group, send email to
> > > > > > cake-php+unsubscr...@googlegroups.com > > > > >  om>
> > 
> > > > > > .
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/cake-php?hl=.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com > om>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=.

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread David Roda
beforeSave is a model callback, not a controller call back.  It needs to go
into your model

On Wed, Nov 18, 2009 at 11:06 PM, jburns  wrote:

> Whenever I have used beforeSave in a controller (not sure if you are
> using this in AppController?) I have called parent::beforeSave();
> first. Really don't know if that will make a difference or not.
>
> On Nov 19, 4:02 am, Dave  wrote:
> > Ok now I have
> >
> > function beforeSave()
> >  {
> >
> > return false;
> >  }
> >
> > so it should fail automatically but it still saves. There has to be
> > something very wrong.
> >
> > Any one have any ideas what so ever? This makes no sense what so ever.
> >
> > Dave
> >
> > On Nov 18, 9:05 pm, Dave  wrote:
> >
> >
> >
> > > I have :
> >
> > > function beforeSave()
> > >   {
> > >   App::import('Core', 'sanitize');
> > >   $this->data = Sanitize::clean($this->data);
> > >   return true;
> > >   }
> >
> > > But no matter what I save nothing happens to the data.
> >
> > > Even tried adding this to the before save
> >
> > > function beforeSave()
> > >   {
> > >   App::import('Core', 'sanitize');
> > >   $this->data = Sanitize::clean($this->data);
> >
> > > if(!empty($this->data))
> > > {
> > > $this->data['Award']['title'] = 'added from
> beforeSave';
> >
> > > }
> > >   return true;
> > >   }
> >
> > > But still nothing.
> >
> > > Any ideas anyone?
> >
> > > On Nov 18, 2:40 am, Erik Nedwidek  wrote:
> >
> > > > Dave,
> >
> > > > No need to call the beforeSave method as it is a callback.
> >
> > > > function beforeSave() {
> > > >   App::import('Sanitize');
> > > >   $this->data = Sanitize::clean($this->data);
> >
> > > >   return true;
> >
> > > > }
> >
> > > > That should be all you need to do. Throw a couple of $this->log()
> statements
> > > > in there to verify the method is being called by Cake if you're not
> sure.
> >
> > > > Erik Nedwidek
> > > > Project Manager
> > > > Lighthouse I.T. Consulting, Inc.
> >
> > > > On Tue, Nov 17, 2009 at 10:37 PM, Dave 
> wrote:
> > > > > Do you manually have to call beforeSave();
> >
> > > > > I have
> > > > > function beforeSave()
> > > > >  {
> > > > >$clean = new Sanitize();
> > > > >$this->data = $clean->clean($this->data);
> > > > > return true;
> >
> > > > >  }
> >
> > > > > But it does nothing to the data.
> >
> > > > > What am I doing wrong?
> >
> > > > > Dave
> >
> > > > > --
> >
> > > > > You received this message because you are subscribed to the Google
> Groups
> > > > > "CakePHP" group.
> > > > > To post to this group, send email to cake-...@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=.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread jburns
Whenever I have used beforeSave in a controller (not sure if you are
using this in AppController?) I have called parent::beforeSave();
first. Really don't know if that will make a difference or not.

On Nov 19, 4:02 am, Dave  wrote:
> Ok now I have
>
> function beforeSave()
>          {
>
>                 return false;
>          }
>
> so it should fail automatically but it still saves. There has to be
> something very wrong.
>
> Any one have any ideas what so ever? This makes no sense what so ever.
>
> Dave
>
> On Nov 18, 9:05 pm, Dave  wrote:
>
>
>
> > I have :
>
> > function beforeSave()
> >       {
> >           App::import('Core', 'sanitize');
> >           $this->data = Sanitize::clean($this->data);
> >           return true;
> >       }
>
> > But no matter what I save nothing happens to the data.
>
> > Even tried adding this to the before save
>
> > function beforeSave()
> >       {
> >           App::import('Core', 'sanitize');
> >           $this->data = Sanitize::clean($this->data);
>
> >                 if(!empty($this->data))
> >                 {
> >                 $this->data['Award']['title'] = 'added from beforeSave';
>
> >                 }
> >           return true;
> >       }
>
> > But still nothing.
>
> > Any ideas anyone?
>
> > On Nov 18, 2:40 am, Erik Nedwidek  wrote:
>
> > > Dave,
>
> > > No need to call the beforeSave method as it is a callback.
>
> > > function beforeSave() {
> > >   App::import('Sanitize');
> > >   $this->data = Sanitize::clean($this->data);
>
> > >   return true;
>
> > > }
>
> > > That should be all you need to do. Throw a couple of $this->log() 
> > > statements
> > > in there to verify the method is being called by Cake if you're not sure.
>
> > > Erik Nedwidek
> > > Project Manager
> > > Lighthouse I.T. Consulting, Inc.
>
> > > On Tue, Nov 17, 2009 at 10:37 PM, Dave  wrote:
> > > > Do you manually have to call beforeSave();
>
> > > > I have
> > > > function beforeSave()
> > > >  {
> > > >        $clean = new Sanitize();
> > > >        $this->data = $clean->clean($this->data);
> > > > return true;
>
> > > >  }
>
> > > > But it does nothing to the data.
>
> > > > What am I doing wrong?
>
> > > > Dave
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "CakePHP" group.
> > > > To post to this group, send email to cake-...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > cake-php+unsubscr...@googlegroups.com > > >  om>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=.

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread Dave
Ok now I have

function beforeSave()
 {



return false;
 }

so it should fail automatically but it still saves. There has to be
something very wrong.

Any one have any ideas what so ever? This makes no sense what so ever.

Dave

On Nov 18, 9:05 pm, Dave  wrote:
> I have :
>
> function beforeSave()
>       {
>           App::import('Core', 'sanitize');
>           $this->data = Sanitize::clean($this->data);
>           return true;
>       }
>
> But no matter what I save nothing happens to the data.
>
> Even tried adding this to the before save
>
> function beforeSave()
>       {
>           App::import('Core', 'sanitize');
>           $this->data = Sanitize::clean($this->data);
>
>                 if(!empty($this->data))
>                 {
>                 $this->data['Award']['title'] = 'added from beforeSave';
>
>                 }
>           return true;
>       }
>
> But still nothing.
>
> Any ideas anyone?
>
> On Nov 18, 2:40 am, Erik Nedwidek  wrote:
>
> > Dave,
>
> > No need to call the beforeSave method as it is a callback.
>
> > function beforeSave() {
> >   App::import('Sanitize');
> >   $this->data = Sanitize::clean($this->data);
>
> >   return true;
>
> > }
>
> > That should be all you need to do. Throw a couple of $this->log() statements
> > in there to verify the method is being called by Cake if you're not sure.
>
> > Erik Nedwidek
> > Project Manager
> > Lighthouse I.T. Consulting, Inc.
>
> > On Tue, Nov 17, 2009 at 10:37 PM, Dave  wrote:
> > > Do you manually have to call beforeSave();
>
> > > I have
> > > function beforeSave()
> > >  {
> > >        $clean = new Sanitize();
> > >        $this->data = $clean->clean($this->data);
> > > return true;
>
> > >  }
>
> > > But it does nothing to the data.
>
> > > What am I doing wrong?
>
> > > Dave
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > > "CakePHP" group.
> > > To post to this group, send email to cake-...@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=.
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-18 Thread Dave
I have :

function beforeSave()
  {
  App::import('Core', 'sanitize');
  $this->data = Sanitize::clean($this->data);
  return true;
  }

But no matter what I save nothing happens to the data.

Even tried adding this to the before save

function beforeSave()
  {
  App::import('Core', 'sanitize');
  $this->data = Sanitize::clean($this->data);

if(!empty($this->data))
{
$this->data['Award']['title'] = 'added from beforeSave';


}
  return true;
  }


But still nothing.

Any ideas anyone?

On Nov 18, 2:40 am, Erik Nedwidek  wrote:
> Dave,
>
> No need to call the beforeSave method as it is a callback.
>
> function beforeSave() {
>   App::import('Sanitize');
>   $this->data = Sanitize::clean($this->data);
>
>   return true;
>
> }
>
> That should be all you need to do. Throw a couple of $this->log() statements
> in there to verify the method is being called by Cake if you're not sure.
>
> Erik Nedwidek
> Project Manager
> Lighthouse I.T. Consulting, Inc.
>
> On Tue, Nov 17, 2009 at 10:37 PM, Dave  wrote:
> > Do you manually have to call beforeSave();
>
> > I have
> > function beforeSave()
> >  {
> >        $clean = new Sanitize();
> >        $this->data = $clean->clean($this->data);
> > return true;
>
> >  }
>
> > But it does nothing to the data.
>
> > What am I doing wrong?
>
> > Dave
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "CakePHP" group.
> > To post to this group, send email to cake-...@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=.

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave?

2009-11-17 Thread Erik Nedwidek
Dave,

No need to call the beforeSave method as it is a callback.

function beforeSave() {
  App::import('Sanitize');
  $this->data = Sanitize::clean($this->data);

  return true;
}

That should be all you need to do. Throw a couple of $this->log() statements
in there to verify the method is being called by Cake if you're not sure.

Erik Nedwidek
Project Manager
Lighthouse I.T. Consulting, Inc.


On Tue, Nov 17, 2009 at 10:37 PM, Dave  wrote:

> Do you manually have to call beforeSave();
>
> I have
> function beforeSave()
>  {
>$clean = new Sanitize();
>$this->data = $clean->clean($this->data);
> return true;
>
>  }
>
> But it does nothing to the data.
>
> What am I doing wrong?
>
> Dave
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-...@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=.




Re: beforeSave() is not called by save()

2009-10-17 Thread Cris Sawfish

Yes!
I figured it out just a while ago!

Thank you very much for your help.
In the fututre I will have to be more carefull :-p

On Oct 17, 5:25 pm, Marc  wrote:
> beforeSave() is defined outside the class.
>
> On 17 okt, 15:41, Cris Sawfish  wrote:
>
> > 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  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  wrote:
>
> > > > Hi to all,
> > > > I have created the following (simple) Model.
>
> > > > 
> > > > 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: beforeSave() is not called by save()

2009-10-17 Thread Marc

beforeSave() is defined outside the class.

On 17 okt, 15:41, Cris Sawfish  wrote:
> 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  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  wrote:
>
> > > Hi to all,
> > > I have created the following (simple) Model.
>
> > > 
> > > 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: beforeSave() is not called by save()

2009-10-17 Thread Cris Sawfish

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  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  wrote:
>
> > Hi to all,
> > I have created the following (simple) Model.
>
> > 
> > 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: beforeSave() is not called by save()

2009-10-16 Thread John Andersen

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  wrote:
> Hi to all,
> I have created the following (simple) Model.
>
> 
> 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: BeforeSave and undefined index

2009-01-14 Thread Kanten

Well, that was a really embarressing error. Especially considering I
used 1 hour trying to debug it.
Thank you very much!

/Anders

On Jan 13, 6:01 pm, grigri  wrote:
> You wrote this:
>
>                $this->data['ArvcProfile']['minor_criteria'] == $minor;
>                 $this->data['ArvcProfile']['major_criteria'] ==
> $major;
>
>                 if ($major > 1 || ($major == 1 && $minor > 1) ||
> ($minor > 3)) {
>                         $this->data['ArvcProfile']
> ['criteria_fulfilled'] == 1;
>                 }
>
> I think you meant this:
>
>                $this->data['ArvcProfile']['minor_criteria'] = $minor;
>                 $this->data['ArvcProfile']['major_criteria'] = $major;
>
>                 if ($major > 1 || ($major == 1 && $minor > 1) ||
> ($minor > 3)) {
>                         $this->data['ArvcProfile']
> ['criteria_fulfilled'] = 1;
>                 }
>
> This sort of typo is frequent the other way around (using = instead of
> ==) and can lead to major hair loss. This way around, I haven't seen
> so much
>
> hth
> grigri
>
> On Jan 13, 4:51 pm, Kanten  wrote:
>
> > Hi,
>
> > I'm trying to do some beforesave massaging in my model but it fails
> > with the error messages:
> > Notice (8): Undefined index:  minor_criteria [APP/models/
> > arvc_profile.php, line 32]
> > Notice (8): Undefined index:  major_criteria [APP/models/
> > arvc_profile.php, line 33]
> > Notice (8): Undefined index:  criteria_fulfilled [APP/models/
> > arvc_profile.php, line 36]
>
> > The threes indexes are not a part of the form, from which the data is
> > derived, but are in the database table, and hence I thought I would be
> > able to manipulate them in my model. My BeforeSave function can be
> > seen below.
>
> > Anyone know what I am doing wrong here.
>
> > function beforeSave() {
> >                 /* Calculates no of major and minor ARVC criterias  */
> >                 $minor = 0;
> >                 $major = 0;
> >                 $total = 0;
> >                 $groups = array();
> >                 if($this->data['ArvcProfile']['rv_sev_dilatation'] == 1) 
> > {$major++;}
> >                 if($this->data['ArvcProfile']['rv_aneurysms'] == 1) 
> > {$major++;}
> >                 if($this->data['ArvcProfile']['rv_sev_seg_dilatation'] == 
> > 1) {$major+
> > +;}
> >                 if($this->data['ArvcProfile']['rv_mild_dilatation'] == 1) 
> > {$minor++;
> > $groups[]=1;}
> >                 if($this->data['ArvcProfile']['rv_mild_seg_dilatation'] == 
> > 1) {$minor
> > ++; $groups[]=1;}
> >                 if($this->data['ArvcProfile']['rv_reg_hypokinesia'] == 1) 
> > {$minor++;
> > $groups[]=1;}
> >                 if($this->data['ArvcProfile']['fibrofatty_replacement'] == 
> > 1) {$major
> > ++;}
> >                 if($this->data['ArvcProfile']['inverted_t_waves'] == 1) 
> > {$minor++;
> > $groups[]=3;}
> >                 if($this->data['ArvcProfile']['epsilon_waves'] == 1) 
> > {$major++;}
> >                 if($this->data['ArvcProfile']['late_potentials'] == 1) 
> > {$minor++;
> > $groups[]=4;}
> >                 if($this->data['ArvcProfile']['lbbb_vt'] == 1) {$minor++; 
> > $groups[]
> > =5;}
> >                 if($this->data['ArvcProfile']['familial_disease'] == 1) 
> > {$major++;}
> >                 if($this->data['ArvcProfile']['familial_sd'] == 1) 
> > {$minor++; $groups
> > []=6;}
> >                 if($this->data['ArvcProfile']['familial_history'] == 1) 
> > {$minor++;
> > $groups[]=6;}
>
> >                 $this->data['ArvcProfile']['minor_criteria'] == $minor;
> >                 $this->data['ArvcProfile']['major_criteria'] == $major;
>
> >                 if ($major > 1 || ($major == 1 && $minor > 1) || ($minor > 
> > 3)) {
> >                         $this->data['ArvcProfile']['criteria_fulfilled'] == 
> > 1;
> >                 }
> >                 return true;
> >         }
>
> > /Anders
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: BeforeSave and undefined index

2009-01-13 Thread grigri

You wrote this:

   $this->data['ArvcProfile']['minor_criteria'] == $minor;
$this->data['ArvcProfile']['major_criteria'] ==
$major;

if ($major > 1 || ($major == 1 && $minor > 1) ||
($minor > 3)) {
$this->data['ArvcProfile']
['criteria_fulfilled'] == 1;
}

I think you meant this:

   $this->data['ArvcProfile']['minor_criteria'] = $minor;
$this->data['ArvcProfile']['major_criteria'] = $major;

if ($major > 1 || ($major == 1 && $minor > 1) ||
($minor > 3)) {
$this->data['ArvcProfile']
['criteria_fulfilled'] = 1;
}

This sort of typo is frequent the other way around (using = instead of
==) and can lead to major hair loss. This way around, I haven't seen
so much

hth
grigri

On Jan 13, 4:51 pm, Kanten  wrote:
> Hi,
>
> I'm trying to do some beforesave massaging in my model but it fails
> with the error messages:
> Notice (8): Undefined index:  minor_criteria [APP/models/
> arvc_profile.php, line 32]
> Notice (8): Undefined index:  major_criteria [APP/models/
> arvc_profile.php, line 33]
> Notice (8): Undefined index:  criteria_fulfilled [APP/models/
> arvc_profile.php, line 36]
>
> The threes indexes are not a part of the form, from which the data is
> derived, but are in the database table, and hence I thought I would be
> able to manipulate them in my model. My BeforeSave function can be
> seen below.
>
> Anyone know what I am doing wrong here.
>
> function beforeSave() {
>                 /* Calculates no of major and minor ARVC criterias  */
>                 $minor = 0;
>                 $major = 0;
>                 $total = 0;
>                 $groups = array();
>                 if($this->data['ArvcProfile']['rv_sev_dilatation'] == 1) 
> {$major++;}
>                 if($this->data['ArvcProfile']['rv_aneurysms'] == 1) 
> {$major++;}
>                 if($this->data['ArvcProfile']['rv_sev_seg_dilatation'] == 1) 
> {$major+
> +;}
>                 if($this->data['ArvcProfile']['rv_mild_dilatation'] == 1) 
> {$minor++;
> $groups[]=1;}
>                 if($this->data['ArvcProfile']['rv_mild_seg_dilatation'] == 1) 
> {$minor
> ++; $groups[]=1;}
>                 if($this->data['ArvcProfile']['rv_reg_hypokinesia'] == 1) 
> {$minor++;
> $groups[]=1;}
>                 if($this->data['ArvcProfile']['fibrofatty_replacement'] == 1) 
> {$major
> ++;}
>                 if($this->data['ArvcProfile']['inverted_t_waves'] == 1) 
> {$minor++;
> $groups[]=3;}
>                 if($this->data['ArvcProfile']['epsilon_waves'] == 1) 
> {$major++;}
>                 if($this->data['ArvcProfile']['late_potentials'] == 1) 
> {$minor++;
> $groups[]=4;}
>                 if($this->data['ArvcProfile']['lbbb_vt'] == 1) {$minor++; 
> $groups[]
> =5;}
>                 if($this->data['ArvcProfile']['familial_disease'] == 1) 
> {$major++;}
>                 if($this->data['ArvcProfile']['familial_sd'] == 1) {$minor++; 
> $groups
> []=6;}
>                 if($this->data['ArvcProfile']['familial_history'] == 1) 
> {$minor++;
> $groups[]=6;}
>
>                 $this->data['ArvcProfile']['minor_criteria'] == $minor;
>                 $this->data['ArvcProfile']['major_criteria'] == $major;
>
>                 if ($major > 1 || ($major == 1 && $minor > 1) || ($minor > 
> 3)) {
>                         $this->data['ArvcProfile']['criteria_fulfilled'] == 1;
>                 }
>                 return true;
>         }
>
> /Anders
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread Sam Sherlock
yep sweet!!   needs some refinement but sweet it works.

happy baking - S

On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
> If you can assume that the settings in actsAs are valid, you can do
> this:
>
> class Photo extends AppModel {
>   var $actsAs = array(
> 'Upload' => array('some' => 'settings')
>   );
>
>
>   function save($data = null, $validate = true, $fieldList = array())
> {
>
> // Prepare new config
> $config = array_merge(
>   $this->actsAs['Upload'],
>   array(
> 'src' => array(
>
>   'dir' => '/' . $this->getEventSlug($this->data['Photo']
> ['event_id'])
>
> )
>   )
> );
> // Detach behavior
> $this->Behaviors->detach('Upload');
> // Re-attach with new params
> $this->Behaviors->attach('Upload', $config);
> // Continue saving normally
>
> return parent::save($data, $validate, $fieldList);
>   }
> }
>
>
> On Apr 2, 3:32 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > but from where do I call the attach detach?
> >
> >  here is what I am planning to try
> >
> >- read the setting of Upload behavior to an array
> >- update the dir setting
> >- detach the set behaviour
> >- attach the modified one
> >
> > where do I use the attach / detach behaviour calls??
> >
>
> > On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Since the introduction of the behaviors collection, I don't think the
> > > code in that article will work as it relies on the behavior objects
> > > being properties of the model, which they aren't any more.
> >
> > > Behaviors can be attached/detached at runtime with the `attach` and
> > > `detach` methods, but reconfiguring depends entirely on the behavior
> > > implementation itself.
> >
> > > On Apr 2, 2:40 pm, "[EMAIL PROTECTED]"
> >
> > > <[EMAIL PROTECTED]> wrote:
> > > > This might be useful to you. It allows you reconfigure the
> behaviours
> > > > as well.
> >
> > > >
> http://www.sanisoft.com/blog/2007/06/26/attach-detach-behaviors-at-ru...
> >
> > > > Simonhttp://www.simonellistonball.com/
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread grigri

If you can assume that the settings in actsAs are valid, you can do
this:

class Photo extends AppModel {
  var $actsAs = array(
'Upload' => array('some' => 'settings')
  );

  function save($data = null, $validate = true, $fieldList = array())
{
// Prepare new config
$config = array_merge(
  $this->actsAs['Upload'],
  array(
'src' => array(
  'dir' => '/' . $this->getEventSlug($this->data['Photo']
['event_id'])
)
  )
);
// Detach behavior
$this->Behaviors->detach('Upload');
// Re-attach with new params
$this->Behaviors->attach('Upload', $config);
// Continue saving normally
return parent::save($data, $validate, $fieldList);
  }
}

On Apr 2, 3:32 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> but from where do I call the attach detach?
>
>  here is what I am planning to try
>
>- read the setting of Upload behavior to an array
>- update the dir setting
>- detach the set behaviour
>- attach the modified one
>
> where do I use the attach / detach behaviour calls??
>
> On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
>
> > Since the introduction of the behaviors collection, I don't think the
> > code in that article will work as it relies on the behavior objects
> > being properties of the model, which they aren't any more.
>
> > Behaviors can be attached/detached at runtime with the `attach` and
> > `detach` methods, but reconfiguring depends entirely on the behavior
> > implementation itself.
>
> > On Apr 2, 2:40 pm, "[EMAIL PROTECTED]"
>
> > <[EMAIL PROTECTED]> wrote:
> > > This might be useful to you. It allows you reconfigure the behaviours
> > > as well.
>
> > >http://www.sanisoft.com/blog/2007/06/26/attach-detach-behaviors-at-ru...
>
> > > Simonhttp://www.simonellistonball.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread Sam Sherlock
but from where do I call the attach detach?

 here is what I am planning to try


   - read the setting of Upload behavior to an array
   - update the dir setting
   - detach the set behaviour
   - attach the modified one

where do I use the attach / detach behaviour calls??

On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
> Since the introduction of the behaviors collection, I don't think the
> code in that article will work as it relies on the behavior objects
> being properties of the model, which they aren't any more.
>
> Behaviors can be attached/detached at runtime with the `attach` and
> `detach` methods, but reconfiguring depends entirely on the behavior
> implementation itself.
>
> On Apr 2, 2:40 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > This might be useful to you. It allows you reconfigure the behaviours
> > as well.
> >
>
> > http://www.sanisoft.com/blog/2007/06/26/attach-detach-behaviors-at-ru...
> >
> > Simonhttp://www.simonellistonball.com/
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread grigri

Since the introduction of the behaviors collection, I don't think the
code in that article will work as it relies on the behavior objects
being properties of the model, which they aren't any more.

Behaviors can be attached/detached at runtime with the `attach` and
`detach` methods, but reconfiguring depends entirely on the behavior
implementation itself.

On Apr 2, 2:40 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> This might be useful to you. It allows you reconfigure the behaviours
> as well.
>
> http://www.sanisoft.com/blog/2007/06/26/attach-detach-behaviors-at-ru...
>
> Simonhttp://www.simonellistonball.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread [EMAIL PROTECTED]

This might be useful to you. It allows you reconfigure the behaviours
as well.

http://www.sanisoft.com/blog/2007/06/26/attach-detach-behaviors-at-run-time-in-cakephp-models/

Simon
http://www.simonellistonball.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread Sam Sherlock
thanks for the information guys.

On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
> Another thing, the actsAs array is only queried when the behavior
> collection is created. Changing it won't (AFAIK) affect the already-
> created behavior. Not 100% sure of the official method of configuring
> at runtime.
>
> How about overriding the save method directly?
>
> class Photo extends AppModel {
>   function save($data = null, $validate = true, $fieldList = array())
> {
> $this->Behaviors->Upload->settings[$this->alias]['src']['dir'] =
>
> '/' . $this->getEventSlug($this->data['Photo']['event_id']);
>
> return parent::save($data, $validate, $fieldList);
>   }
> }
>
> (Note that depending on the behavior you use, you might need to use
> $this->name instead of $this->alias - check how the config is keyed in
> the behavior setup method)
>
> On Apr 2, 1:35 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Another way to do it is to write a behaviour which does the alteration
> > and include that in the actsAs array before the upload behaviour. They
> > are run in order, so the upload behaviour will see what your behaviour
> > did. That way you don't need to mess with the 3rd party code.
> >
>
> > Simonhttp://www.simonellistonball.com/
>
> >
> > On Apr 2, 1:30 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> >
> > > yep just seen that.  Guess that means no then can't be done.
> >
> > > Unless customise the behaviour.
> >
> > > I guess there is a reason for behaviors beforeSave being called before
> the
> > > models beforeSave
> >
> > > On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
> >
> > > > Behavior beforeSave() callbacks are called before the Model's
> > > > beforeSave() callback.
> >
> > > > On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > > > > I have and Event Model that hasMany Photos
> >
> > > > > I am using an upload behaviour and wish to save photos in a
> directory by
> > > > the
> > > > > event Slug
> >
> > > > > the below code is in the photo model the actsAs infor is updated
> but the
> > > > new
> > > > > information is ignored
> >
> > > > > function beforeSave() {
> > > > > $this->actsAs['Upload']['src']['dir'].= '/' .
> > > > > $this->getEventSlug($this->data['Photo']['event_id']);
> > > > > return true;
> > > > > }
> >
> > > > > how can I get this to work?
> >
> > > > > - S
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread grigri

Another thing, the actsAs array is only queried when the behavior
collection is created. Changing it won't (AFAIK) affect the already-
created behavior. Not 100% sure of the official method of configuring
at runtime.

How about overriding the save method directly?

class Photo extends AppModel {
  function save($data = null, $validate = true, $fieldList = array())
{
$this->Behaviors->Upload->settings[$this->alias]['src']['dir'] =
'/' . $this->getEventSlug($this->data['Photo']['event_id']);
return parent::save($data, $validate, $fieldList);
  }
}

(Note that depending on the behavior you use, you might need to use
$this->name instead of $this->alias - check how the config is keyed in
the behavior setup method)

On Apr 2, 1:35 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Another way to do it is to write a behaviour which does the alteration
> and include that in the actsAs array before the upload behaviour. They
> are run in order, so the upload behaviour will see what your behaviour
> did. That way you don't need to mess with the 3rd party code.
>
> Simonhttp://www.simonellistonball.com/
>
> On Apr 2, 1:30 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
>
> > yep just seen that.  Guess that means no then can't be done.
>
> > Unless customise the behaviour.
>
> > I guess there is a reason for behaviors beforeSave being called before the
> > models beforeSave
>
> > On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Behavior beforeSave() callbacks are called before the Model's
> > > beforeSave() callback.
>
> > > On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > > > I have and Event Model that hasMany Photos
>
> > > > I am using an upload behaviour and wish to save photos in a directory by
> > > the
> > > > event Slug
>
> > > > the below code is in the photo model the actsAs infor is updated but the
> > > new
> > > > information is ignored
>
> > > > function beforeSave() {
> > > > $this->actsAs['Upload']['src']['dir'].= '/' .
> > > > $this->getEventSlug($this->data['Photo']['event_id']);
> > > > return true;
> > > > }
>
> > > > how can I get this to work?
>
> > > > - S
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread [EMAIL PROTECTED]

Another way to do it is to write a behaviour which does the alteration
and include that in the actsAs array before the upload behaviour. They
are run in order, so the upload behaviour will see what your behaviour
did. That way you don't need to mess with the 3rd party code.

Simon
http://www.simonellistonball.com/

On Apr 2, 1:30 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> yep just seen that.  Guess that means no then can't be done.
>
> Unless customise the behaviour.
>
> I guess there is a reason for behaviors beforeSave being called before the
> models beforeSave
>
> On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
>
> > Behavior beforeSave() callbacks are called before the Model's
> > beforeSave() callback.
>
> > On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > > I have and Event Model that hasMany Photos
>
> > > I am using an upload behaviour and wish to save photos in a directory by
> > the
> > > event Slug
>
> > > the below code is in the photo model the actsAs infor is updated but the
> > new
> > > information is ignored
>
> > > function beforeSave() {
> > > $this->actsAs['Upload']['src']['dir'].= '/' .
> > > $this->getEventSlug($this->data['Photo']['event_id']);
> > > return true;
> > > }
>
> > > how can I get this to work?
>
> > > - S
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread Sam Sherlock
yep just seen that.  Guess that means no then can't be done.

Unless customise the behaviour.

I guess there is a reason for behaviors beforeSave being called before the
models beforeSave


On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
>
> Behavior beforeSave() callbacks are called before the Model's
> beforeSave() callback.
>
>
> On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > I have and Event Model that hasMany Photos
> >
> > I am using an upload behaviour and wish to save photos in a directory by
> the
> > event Slug
> >
> > the below code is in the photo model the actsAs infor is updated but the
> new
> > information is ignored
> >
> > function beforeSave() {
> > $this->actsAs['Upload']['src']['dir'].= '/' .
> > $this->getEventSlug($this->data['Photo']['event_id']);
> > return true;
> > }
> >
> > how can I get this to work?
> >
> > - S
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave & behaviours

2008-04-02 Thread grigri

Behavior beforeSave() callbacks are called before the Model's
beforeSave() callback.

On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> I have and Event Model that hasMany Photos
>
> I am using an upload behaviour and wish to save photos in a directory by the
> event Slug
>
> the below code is in the photo model the actsAs infor is updated but the new
> information is ignored
>
> function beforeSave() {
> $this->actsAs['Upload']['src']['dir'].= '/' .
> $this->getEventSlug($this->data['Photo']['event_id']);
> return true;
> }
>
> how can I get this to work?
>
> - S
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Brian

OK I think I've got it now, thank you both very much for your help.

On Jul 5, 1:44 pm, Walker Hamilton <[EMAIL PROTECTED]> wrote:
> Yeah, what ketan said.
>
> It's not telling your model to use a callback. it's making it so that
> multiple levels of the (inherited) beforeSave function ( App Model
> Class -> Model Name Class ) all get run.
>
> On Jul 5, 1:33 pm, Ketan Patel <[EMAIL PROTECTED]> wrote:
>
> > If you defined  function beforeSave() in your controller then
> > essentially you are overriding the beforeSave function defined in
> > AppController and its parent Controller.
>
> > So by calling parent::beforeSave() you are telling, you want to call
> > the beforeSave method of the parent class which AppController.
>
> > Ketan
>
> > Brian wrote:
> > > Ah, I see now. Thanks for spelling that out for me. It works quite
> > > well :)
>
> > > So parent::beforeSave() essentially tells the model to use the
> > > beforeSave callback?
> > > Walker Hamilton wrote:
> > > > function beforeSave()
> > > > {
>
> > > > if(isset($this->data['ItemData']['common_name']))
> > > > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
>
> > > > return parent::beforeSave();
> > > > }
>
> > > > On Jul 5, 12:54 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > > I'm still a little confused.
>
> > > > > So I keep what I have right now ($this->data[) in my beforeSave()
> > > > > and then do what?
>
> > > > > Walker Hamilton wrote:
> > > > > > you shouldn't need to create a hidden field called 'name'.
>
> > > > > > just do the assignation in beforeSave.
>
> > > > > > you need to make sure your beforeSave in the model returns
> > > > > > parent::beforeSave
>
> > > > > > On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > > > > Here's a quick synopsis of the scenario: There's a menu, which has
> > > > > > > items, and these have a name and price. I also have a table in a
> > > > > > > separate database that has a ton of information on every item. 
> > > > > > > I've
> > > > > > > got an AutoCompleter set up with this third table(ItemData, field
> > > > > > > 'common_name') and what I would like to do is take whatever value 
> > > > > > > is
> > > > > > > in the AutoCompleted input field when the form is submitted and 
> > > > > > > treat
> > > > > > > it as the 'name' property for the Item.
>
> > > > > > > My initial thought was to use the beforeSave() function in my Item
> > > > > > > model with something like this:
>
> > > > > > > $this->data['Item']['name'] = 
> > > > > > > $this->data['ItemData']['common_name'];
>
> > > > > > > I made a hidden field with the name attribute as 
> > > > > > > "data[Item][name]"
> > > > > > > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Brian

I'm still a little confused.

So I keep what I have right now ($this->data[) in my beforeSave()
and then do what?
Walker Hamilton wrote:
> you shouldn't need to create a hidden field called 'name'.
>
> just do the assignation in beforeSave.
>
> you need to make sure your beforeSave in the model returns
> parent::beforeSave
>
> On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > Here's a quick synopsis of the scenario: There's a menu, which has
> > items, and these have a name and price. I also have a table in a
> > separate database that has a ton of information on every item. I've
> > got an AutoCompleter set up with this third table(ItemData, field
> > 'common_name') and what I would like to do is take whatever value is
> > in the AutoCompleted input field when the form is submitted and treat
> > it as the 'name' property for the Item.
> >
> > My initial thought was to use the beforeSave() function in my Item
> > model with something like this:
> >
> > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
> >
> > I made a hidden field with the name attribute as "data[Item][name]"
> > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Walker Hamilton

Yeah, what ketan said.

It's not telling your model to use a callback. it's making it so that
multiple levels of the (inherited) beforeSave function ( App Model
Class -> Model Name Class ) all get run.

On Jul 5, 1:33 pm, Ketan Patel <[EMAIL PROTECTED]> wrote:
> If you defined  function beforeSave() in your controller then
> essentially you are overriding the beforeSave function defined in
> AppController and its parent Controller.
>
> So by calling parent::beforeSave() you are telling, you want to call
> the beforeSave method of the parent class which AppController.
>
> Ketan
>
> Brian wrote:
> > Ah, I see now. Thanks for spelling that out for me. It works quite
> > well :)
>
> > So parent::beforeSave() essentially tells the model to use the
> > beforeSave callback?
> > Walker Hamilton wrote:
> > > function beforeSave()
> > > {
>
> > > if(isset($this->data['ItemData']['common_name']))
> > > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
>
> > > return parent::beforeSave();
> > > }
>
> > > On Jul 5, 12:54 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > I'm still a little confused.
>
> > > > So I keep what I have right now ($this->data[) in my beforeSave()
> > > > and then do what?
>
> > > > Walker Hamilton wrote:
> > > > > you shouldn't need to create a hidden field called 'name'.
>
> > > > > just do the assignation in beforeSave.
>
> > > > > you need to make sure your beforeSave in the model returns
> > > > > parent::beforeSave
>
> > > > > On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > > > Here's a quick synopsis of the scenario: There's a menu, which has
> > > > > > items, and these have a name and price. I also have a table in a
> > > > > > separate database that has a ton of information on every item. I've
> > > > > > got an AutoCompleter set up with this third table(ItemData, field
> > > > > > 'common_name') and what I would like to do is take whatever value is
> > > > > > in the AutoCompleted input field when the form is submitted and 
> > > > > > treat
> > > > > > it as the 'name' property for the Item.
>
> > > > > > My initial thought was to use the beforeSave() function in my Item
> > > > > > model with something like this:
>
> > > > > > $this->data['Item']['name'] = 
> > > > > > $this->data['ItemData']['common_name'];
>
> > > > > > I made a hidden field with the name attribute as "data[Item][name]"
> > > > > > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Ketan Patel

If you defined  function beforeSave() in your controller then
essentially you are overriding the beforeSave function defined in
AppController and its parent Controller.

So by calling parent::beforeSave() you are telling, you want to call
the beforeSave method of the parent class which AppController.

Ketan

Brian wrote:
> Ah, I see now. Thanks for spelling that out for me. It works quite
> well :)
>
> So parent::beforeSave() essentially tells the model to use the
> beforeSave callback?
> Walker Hamilton wrote:
> > function beforeSave()
> > {
> >
> > if(isset($this->data['ItemData']['common_name']))
> > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
> >
> > return parent::beforeSave();
> > }
> >
> >
> >
> > On Jul 5, 12:54 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > I'm still a little confused.
> > >
> > > So I keep what I have right now ($this->data[) in my beforeSave()
> > > and then do what?
> > >
> > > Walker Hamilton wrote:
> > > > you shouldn't need to create a hidden field called 'name'.
> > >
> > > > just do the assignation in beforeSave.
> > >
> > > > you need to make sure your beforeSave in the model returns
> > > > parent::beforeSave
> > >
> > > > On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > > Here's a quick synopsis of the scenario: There's a menu, which has
> > > > > items, and these have a name and price. I also have a table in a
> > > > > separate database that has a ton of information on every item. I've
> > > > > got an AutoCompleter set up with this third table(ItemData, field
> > > > > 'common_name') and what I would like to do is take whatever value is
> > > > > in the AutoCompleted input field when the form is submitted and treat
> > > > > it as the 'name' property for the Item.
> > >
> > > > > My initial thought was to use the beforeSave() function in my Item
> > > > > model with something like this:
> > >
> > > > > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
> > >
> > > > > I made a hidden field with the name attribute as "data[Item][name]"
> > > > > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Brian

Ah, I see now. Thanks for spelling that out for me. It works quite
well :)

So parent::beforeSave() essentially tells the model to use the
beforeSave callback?
Walker Hamilton wrote:
> function beforeSave()
> {
>
> if(isset($this->data['ItemData']['common_name']))
> $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
>
> return parent::beforeSave();
> }
>
>
>
> On Jul 5, 12:54 pm, Brian <[EMAIL PROTECTED]> wrote:
> > I'm still a little confused.
> >
> > So I keep what I have right now ($this->data[) in my beforeSave()
> > and then do what?
> >
> > Walker Hamilton wrote:
> > > you shouldn't need to create a hidden field called 'name'.
> >
> > > just do the assignation in beforeSave.
> >
> > > you need to make sure your beforeSave in the model returns
> > > parent::beforeSave
> >
> > > On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > > Here's a quick synopsis of the scenario: There's a menu, which has
> > > > items, and these have a name and price. I also have a table in a
> > > > separate database that has a ton of information on every item. I've
> > > > got an AutoCompleter set up with this third table(ItemData, field
> > > > 'common_name') and what I would like to do is take whatever value is
> > > > in the AutoCompleted input field when the form is submitted and treat
> > > > it as the 'name' property for the Item.
> >
> > > > My initial thought was to use the beforeSave() function in my Item
> > > > model with something like this:
> >
> > > > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
> >
> > > > I made a hidden field with the name attribute as "data[Item][name]"
> > > > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Walker Hamilton

function beforeSave()
{

if(isset($this->data['ItemData']['common_name']))
$this->data['Item']['name'] = $this->data['ItemData']['common_name'];

return parent::beforeSave();
}



On Jul 5, 12:54 pm, Brian <[EMAIL PROTECTED]> wrote:
> I'm still a little confused.
>
> So I keep what I have right now ($this->data[) in my beforeSave()
> and then do what?
>
> Walker Hamilton wrote:
> > you shouldn't need to create a hidden field called 'name'.
>
> > just do the assignation in beforeSave.
>
> > you need to make sure your beforeSave in the model returns
> > parent::beforeSave
>
> > On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> > > Here's a quick synopsis of the scenario: There's a menu, which has
> > > items, and these have a name and price. I also have a table in a
> > > separate database that has a ton of information on every item. I've
> > > got an AutoCompleter set up with this third table(ItemData, field
> > > 'common_name') and what I would like to do is take whatever value is
> > > in the AutoCompleted input field when the form is submitted and treat
> > > it as the 'name' property for the Item.
>
> > > My initial thought was to use the beforeSave() function in my Item
> > > model with something like this:
>
> > > $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
>
> > > I made a hidden field with the name attribute as "data[Item][name]"
> > > but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave question

2007-07-05 Thread Walker Hamilton

you shouldn't need to create a hidden field called 'name'.

just do the assignation in beforeSave.

you need to make sure your beforeSave in the model returns
parent::beforeSave

On Jul 5, 12:19 pm, Brian <[EMAIL PROTECTED]> wrote:
> Here's a quick synopsis of the scenario: There's a menu, which has
> items, and these have a name and price. I also have a table in a
> separate database that has a ton of information on every item. I've
> got an AutoCompleter set up with this third table(ItemData, field
> 'common_name') and what I would like to do is take whatever value is
> in the AutoCompleted input field when the form is submitted and treat
> it as the 'name' property for the Item.
>
> My initial thought was to use the beforeSave() function in my Item
> model with something like this:
>
> $this->data['Item']['name'] = $this->data['ItemData']['common_name'];
>
> I made a hidden field with the name attribute as "data[Item][name]"
> but it doesn't work. Anyone else done something like this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

Well, today is Tuesday the 13th. Down here, in Argentina, and I think the
rest of Latin America, Tuesdays the 13th is considered to be a day of bad
luck (Americans believe it's Friday the 13th.)

I agree with you woods, let's keep trying to help other bakers. As long as
there's a community behind Cake, then Cake is worth it. Like Larry once
said, Cake is not (and shouldn't be) a one man show. So let's keep it that
way.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de the_woodsman
Enviado el: Martes, 13 de Febrero de 2007 01:56 p.m.
Para: Cake PHP
Asunto: Re: beforeSave problem (1.2)

Indeed Mariano,

If everyone on this board waited until they knew cake back to front
and upside down before posting, no one would post - and in lieu of
more documentation, this board is what keeps Cake alive and growing.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

Oh well... Let's just drop it here. This is pointless.

To Amon, whom I wrote originally: sorry for the confusion. So you know, I
had in mind the validates() method when I told you to avoid sending $data.

As it happens, I was on vacations when I read on a post that Larry pointed
out that sending $data to validates() was deprecated, and throughout my
vacations I was remembering myself: need to check the code to avoid doing
that. 

On the trip back, my internal hard drive (that thing others call memory) got
mixed up and replaced the word validates() with save(). That's all there was
to it.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de nate
Enviado el: Martes, 13 de Febrero de 2007 02:17 p.m.
Para: Cake PHP
Asunto: Re: beforeSave problem (1.2)

Perhaps I expected too much of Mariano.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave problem (1.2)

2007-02-13 Thread nate

Perhaps I came down a little hard, and not that you don't make a good
point, but the facts are that (a) we *have* been having a problem with
this issue lately, and (b) it's always a fine balance, as we saw with
the wiki; that's why we have the Bakery now, so we can ensure the
quality and accuracy of the information we're making available.  No
one wants to turn this into a situation where we're controlling all
information about the project (least of all us, because it's too much
work and we don't have the resources), but at the same time, confused
do we allow newcomers to the project to get before doing something
about it?  I try to stay active on the mailing list, but I can't do
everything myself.

Perhaps I expected too much of Mariano.

On Feb 13, 11:55 am, "the_woodsman" <[EMAIL PROTECTED]> wrote:
> Indeed Mariano,
>
> If everyone on this board waited until they knew cake back to front
> and upside down before posting, no one would post - and in lieu of
> more documentation, this board is what keeps Cake alive and growing.
>
> If there was more/any documentation for Cake 1.2, then these kinds of
> errors would be very unlikely.
>
> Whenever anyone brings up documentation, Cake devs mention that we're
> all free to contribute, and in fact they encourage it, although anyone
> reading Nate's reaction to someone just trying to help a fellow baker
> would clearly be discouraged from helping the documentation effort - I
> know I am. What if I get something wrong!?
> In fact, isn't this exactly what happened with the wiki? Users tried
> to contribute to the documentation, and it was stopped becuase of
> innacuracies/errors.
>
> Mariano, I'd rather you kept trying and got it wrong occasionally than
> stopped!
>
> And Nate, no offence meant - your posts on this board are absolutely
> vital.
>
> On Feb 13, 4:06 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
> wrote:
>
> > Wow. Got the message.
>
> > I didn't recommend formatting the computer and then seeing what happens. I
> > just got the validates() $data thingy confused with the save(). For the
> > record, nothing gets me more upset that lack of patience.
>
> > -MI
>
> > ---
>
> > Remember, smart coders answer ten questions for every question they ask.
> > So be smart, be cool, and share your knowledge.
>
> > BAKE ON!
>
> > blog:http://www.MarianoIglesias.com.ar
>
> > -Mensaje original-
> > De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> > de nate
> > Enviado el: Martes, 13 de Febrero de 2007 12:16 p.m.
> > Para: Cake PHP
> > Asunto: Re: beforeSave problem (1.2)
>
> > No, bad, wrong, incorrect. categorically false.  Parameter usage has
> > been deprecated for Model::validates() and Model::invalidFields().  If
> > there is something you are or aren't supposed to do, either PhpNut or
> > myself will say so either in the form of documentation, or a friendly
> > warning in the code.
>
> > Also, for the record, nothing gets me more upset than people spreading
> > misinformation.  If you want to help people out, great, just make very
> > *very* sure that you actually know what you're talking about.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

I understand how misinformation affects a lot of people, not just the one
you told.

Throughout this past few months I think I've shown that I do not only
respect the work you do, but also try to evangelize on others to do as well.
I've been collaborating on any aspect I can and I intend to do so in the
future.

So if every now and then I get something wrong, there's no need to snap.

There are ways and ways of saying things. I can understand getting upset
when someone has a demanding attitude, but I don't believe that's my case.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de nate
Enviado el: Martes, 13 de Febrero de 2007 01:52 p.m.
Para: Cake PHP
Asunto: Re: beforeSave problem (1.2)

The problem with misinformation is that it's like playing telephone.
You don't just negatively impact the person you told.  You also impact
the people he tells, and so on and so forth.  Before you know it, mass
confusion.  Granted, the fact that the documentation effort has not
been keeping pace with development doesn't help, but giving people bad
information, however unintentional, only serves to aggravate the
situation, and lately we've been dealing with altogether too much
aggravation and bad information.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave problem (1.2)

2007-02-13 Thread the_woodsman

Indeed Mariano,

If everyone on this board waited until they knew cake back to front
and upside down before posting, no one would post - and in lieu of
more documentation, this board is what keeps Cake alive and growing.

If there was more/any documentation for Cake 1.2, then these kinds of
errors would be very unlikely.

Whenever anyone brings up documentation, Cake devs mention that we're
all free to contribute, and in fact they encourage it, although anyone
reading Nate's reaction to someone just trying to help a fellow baker
would clearly be discouraged from helping the documentation effort - I
know I am. What if I get something wrong!?
In fact, isn't this exactly what happened with the wiki? Users tried
to contribute to the documentation, and it was stopped becuase of
innacuracies/errors.

Mariano, I'd rather you kept trying and got it wrong occasionally than
stopped!

And Nate, no offence meant - your posts on this board are absolutely
vital.



On Feb 13, 4:06 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> Wow. Got the message.
>
> I didn't recommend formatting the computer and then seeing what happens. I
> just got the validates() $data thingy confused with the save(). For the
> record, nothing gets me more upset that lack of patience.
>
> -MI
>
> ---
>
> Remember, smart coders answer ten questions for every question they ask.
> So be smart, be cool, and share your knowledge.
>
> BAKE ON!
>
> blog:http://www.MarianoIglesias.com.ar
>
> -Mensaje original-
> De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> de nate
> Enviado el: Martes, 13 de Febrero de 2007 12:16 p.m.
> Para: Cake PHP
> Asunto: Re: beforeSave problem (1.2)
>
> No, bad, wrong, incorrect. categorically false.  Parameter usage has
> been deprecated for Model::validates() and Model::invalidFields().  If
> there is something you are or aren't supposed to do, either PhpNut or
> myself will say so either in the form of documentation, or a friendly
> warning in the code.
>
> Also, for the record, nothing gets me more upset than people spreading
> misinformation.  If you want to help people out, great, just make very
> *very* sure that you actually know what you're talking about.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave problem (1.2)

2007-02-13 Thread nate

The problem with misinformation is that it's like playing telephone.
You don't just negatively impact the person you told.  You also impact
the people he tells, and so on and so forth.  Before you know it, mass
confusion.  Granted, the fact that the documentation effort has not
been keeping pace with development doesn't help, but giving people bad
information, however unintentional, only serves to aggravate the
situation, and lately we've been dealing with altogether too much
aggravation and bad information.

On Feb 13, 11:06 am, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> Wow. Got the message.
>
> I didn't recommend formatting the computer and then seeing what happens. I
> just got the validates() $data thingy confused with the save(). For the
> record, nothing gets me more upset that lack of patience.
>
> -MI
>
> ---
>
> Remember, smart coders answer ten questions for every question they ask.
> So be smart, be cool, and share your knowledge.
>
> BAKE ON!
>
> blog:http://www.MarianoIglesias.com.ar
>
> -Mensaje original-
> De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> de nate
> Enviado el: Martes, 13 de Febrero de 2007 12:16 p.m.
> Para: Cake PHP
> Asunto: Re: beforeSave problem (1.2)
>
> No, bad, wrong, incorrect. categorically false.  Parameter usage has
> been deprecated for Model::validates() and Model::invalidFields().  If
> there is something you are or aren't supposed to do, either PhpNut or
> myself will say so either in the form of documentation, or a friendly
> warning in the code.
>
> Also, for the record, nothing gets me more upset than people spreading
> misinformation.  If you want to help people out, great, just make very
> *very* sure that you actually know what you're talking about.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

Wow. Got the message. 

I didn't recommend formatting the computer and then seeing what happens. I
just got the validates() $data thingy confused with the save(). For the
record, nothing gets me more upset that lack of patience.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de nate
Enviado el: Martes, 13 de Febrero de 2007 12:16 p.m.
Para: Cake PHP
Asunto: Re: beforeSave problem (1.2)

No, bad, wrong, incorrect. categorically false.  Parameter usage has
been deprecated for Model::validates() and Model::invalidFields().  If
there is something you are or aren't supposed to do, either PhpNut or
myself will say so either in the form of documentation, or a friendly
warning in the code.

Also, for the record, nothing gets me more upset than people spreading
misinformation.  If you want to help people out, great, just make very
*very* sure that you actually know what you're talking about.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave problem (1.2)

2007-02-13 Thread nate

> As of CakePHP 1.2 save() no longer expects the data. Use create() to specify
> it.

No, bad, wrong, incorrect. categorically false.  Parameter usage has
been deprecated for Model::validates() and Model::invalidFields().  If
there is something you are or aren't supposed to do, either PhpNut or
myself will say so either in the form of documentation, or a friendly
warning in the code.

Also, for the record, nothing gets me more upset than people spreading
misinformation.  If you want to help people out, great, just make very
*very* sure that you actually know what you're talking about.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

By "may soon be removed" I didn't mean to say that the save() method would
be removed (duh!), but that the support for sending data to save() may be.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: Mariano Iglesias [mailto:[EMAIL PROTECTED] 
Enviado el: Martes, 13 de Febrero de 2007 11:24 a.m.
Para: 'cake-php@googlegroups.com'
Asunto: RE: beforeSave problem (1.2)

but, unlike create(), it is not considering default values that the table
may have, and may soon be removed, so eventhough you may be inclined to send
data to save(), try to avoid it.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

$this->Model->create() would create an "empty" model, cleaning it of old
values it may have. If you look at cake/libs/model/model.php you'll see that
create is defined as following:

function create($data = array())

So no parameters would be the same as sending it an empty array().

Also on model.php you can see that save() still gets the data:

save($data = null, $validate = true, $fieldList = array())

but, unlike create(), it is not considering default values that the table
may have, and may soon be removed, so eventhough you may be inclined to send
data to save(), try to avoid it.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de Ámon Tamás
Enviado el: Martes, 13 de Febrero de 2007 10:59 a.m.
Para: cake-php@googlegroups.com
Asunto: Re: beforeSave problem (1.2)

Is it $this->Classad->create() same? How I see what the bake.php make 
there is no parameters for create().


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave problem (1.2)

2007-02-13 Thread Ámon Tamás

Mariano Iglesias wrote:
> If you are using CakePHP 1.2 (as you stated) then do not pass $data to the
> save model, instead first construct the model with your data and then call
> save:
> 
> $this->Classad->create($this->data);

Is it $this->Classad->create() same? How I see what the bake.php make 
there is no parameters for create().

-- 
Ámon Tamás
http://linkfelho.amon.hu


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias

If you are using CakePHP 1.2 (as you stated) then do not pass $data to the
save model, instead first construct the model with your data and then call
save:

$this->Classad->create($this->data);
$this->Classad->save();

As of CakePHP 1.2 save() no longer expects the data. Use create() to specify
it.

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de Ámon Tamás
Enviado el: Martes, 13 de Febrero de 2007 06:04 a.m.
Para: Cake PHP
Asunto: beforeSave problem (1.2)

I have a beforeSave() in my Classadd model. In here I adding some extra 
value for the database row, somethind like this:

$this->data['Classadd']['emailazon'] = $this->RandString(24);

but, when I try to get back this data after the
$this->Classadd->save($this->data)

In the $this->Classadd->data is empty. (The insertion is good.) That was 
working in the last stable version. Is this a bug or a new feature?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave return false, what with afterFind...?!

2007-02-11 Thread Seb

If anybody is interested in that thread, solution 1 and 2 proposed by
Nate don't work because merging two arrays recursively returns
something like this;

[code]
Array
(
[Article] => Array
(
[id] => Array
(
[0] => 1
[1] => 1
)
[title] => Array
(
[0] => This is some MODIFIED title
[1] => This is some title
[/code]

The last solution does work, but requires a fair bit of time to
implement and make creating a new virtual field a pain.

I'll keep looking into it!

Cheers,

Seb.



On Jan 22, 4:51 pm, "nate" <[EMAIL PROTECTED]> wrote:
> Sorry, didn't see you the first time.  Okay, as I see it, there are 4
> ways to solve your problem, 3 of which are basically variations on the
> same theme.  The first three ways are these:
>
> // Controller: re-query your entire User model, and merge it with
> $this->data:
> $this->data = array_merge_recursive($this->User->findById($id),
> $this->data);
>
> // Controller: slightly optimized version of the above:
> $user = list($this->User->findById($id, array('relevant', 'fields',
> 'only')));
> $this->data['User']['name_if'] = $user['name_if'];
>
> // Controller: just re-query and blow away the POST data completely:
> $this->data = $this->User->findById($id);
>
> And the final solution is view based:
> // Add a hidden field for the virtual field, to persist it across
> pages:
> hidden("User/name_if"); ?>
>
> - Nate
>   "You know my name, Google the number."


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave return false, what with afterFind...?!

2007-01-21 Thread nate

Sorry, didn't see you the first time.  Okay, as I see it, there are 4
ways to solve your problem, 3 of which are basically variations on the
same theme.  The first three ways are these:

// Controller: re-query your entire User model, and merge it with
$this->data:
$this->data = array_merge_recursive($this->User->findById($id),
$this->data);

// Controller: slightly optimized version of the above:
$user = list($this->User->findById($id, array('relevant', 'fields',
'only')));
$this->data['User']['name_if'] = $user['name_if'];

// Controller: just re-query and blow away the POST data completely:
$this->data = $this->User->findById($id);

And the final solution is view based:
// Add a hidden field for the virtual field, to persist it across
pages:
hidden("User/name_if"); ?>

- Nate
  "You know my name, Google the number."


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave return false, what with afterFind...?!

2007-01-21 Thread Seb

mmm... are ^^BUMPS^^ ok in google groups...?!

;)

Seb.

On Jan 8, 10:06 am, "Seb" <[EMAIL PROTECTED]> wrote:
> Hey Nate,
>
> Thanks for your time! What I'm trying to do evolves around virtual
> fields. For instance in the user model, the afterFind() method creates
> 2 virtual fields, one named name_lf and containing a user full name in
> 'lastname, firstname' format. This works like a charm.
>
> Now if I edit a user, and save my changes, if the beforeSave() in the
> User Model returns false, nothing is saved to the db, and the 'error
> mode' is triggered, the edit form shown again. (that's a pretty
> standard cake behaviour)
>
> Now that's from where my question was raised; because the user data is
> stored in the post, it's not pulled from the DB again - which is great.
> However because it's not pulled again, the afterFind() in the User
> Model is not called, and the name_lf virtual field not created. Because
> of that and because I'm using this virtual field in the edit form, I
> get an error about this name_lf not being defined, hence my question,
> when should a beforeSave return false..?!
>
> Code?
> function afterFind($results) {
> if (is_array($results)) {
> foreach ($results as $key => $obj) {
> if (!isset($obj[$this->name]['id'])) {
> continue;
> }
> $results[$key][$this->name]['name_lf'] =
> ($obj[$this->name]['lname'] ? $obj[$this->name]['lname'] . ', ' : '') .
> $obj[$this->name]['fname'];
> }
> }
> return parent::afterFind($results);
>  }
>
> function beforeSave() {
> // say I was to do something here... db related or not... and
> something fails... which is possible according to the manual
> return false;
>
> } end code
>
> So.. yeah... I don't think I'm doing anything wrong... and am just
> wondering why this all could be...
>
> Cheers!
>
> Seb.
>
> On Jan 6, 5:09 am, "nate" <[EMAIL PROTECTED]> wrote:
>
> > Ummm.  beforeSave() and afterFind() are normally completely
> > unrelated.  It might help to post a code sample so we can see what it
> > is that you're trying to do.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave return false, what with afterFind...?!

2007-01-07 Thread Seb


Hey Nate,

Thanks for your time! What I'm trying to do evolves around virtual
fields. For instance in the user model, the afterFind() method creates
2 virtual fields, one named name_lf and containing a user full name in
'lastname, firstname' format. This works like a charm.

Now if I edit a user, and save my changes, if the beforeSave() in the
User Model returns false, nothing is saved to the db, and the 'error
mode' is triggered, the edit form shown again. (that's a pretty
standard cake behaviour)

Now that's from where my question was raised; because the user data is
stored in the post, it's not pulled from the DB again - which is great.
However because it's not pulled again, the afterFind() in the User
Model is not called, and the name_lf virtual field not created. Because
of that and because I'm using this virtual field in the edit form, I
get an error about this name_lf not being defined, hence my question,
when should a beforeSave return false..?!

Code?
function afterFind($results) {
   if (is_array($results)) {
   foreach ($results as $key => $obj) {
   if (!isset($obj[$this->name]['id'])) {
   continue;
   }
   $results[$key][$this->name]['name_lf'] =
($obj[$this->name]['lname'] ? $obj[$this->name]['lname'] . ', ' : '') .
$obj[$this->name]['fname'];
   }
   }
   return parent::afterFind($results);
}

function beforeSave() {
   // say I was to do something here... db related or not... and
something fails... which is possible according to the manual
   return false;
}

 end code


So.. yeah... I don't think I'm doing anything wrong... and am just
wondering why this all could be...

Cheers!

Seb.


On Jan 6, 5:09 am, "nate" <[EMAIL PROTECTED]> wrote:

Ummm.  beforeSave() and afterFind() are normally completely
unrelated.  It might help to post a code sample so we can see what it
is that you're trying to do.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave return false, what with afterFind...?!

2007-01-05 Thread nate


Ummm.  beforeSave() and afterFind() are normally completely
unrelated.  It might help to post a code sample so we can see what it
is that you're trying to do.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-27 Thread carlosrg

Ok,

I will have a look at it.

Thanks everybody!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-26 Thread Ismael S. Kafeltz

I'm not sure about this, but see this:

http://manual.cakephp.org/appendix/simple_user_auth

In session 03: Access Checking in your Application

You could follow the same ideia, put your code in AppController and
extend it.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-26 Thread carlosrg

It's a shame it can't be.

I wanted to save the username automatically... Now I have to put the
code '$this->Model->set('user_id', $this->Session->read('User.id'));'
in every controller.

Do you know a better way to do it?

Thanks a lot!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-25 Thread nate

Models aren't supposed to have access to the session.  What you can do
is, if your model has a 'user_id' field (or equivalent), you can do
something like this in your controller:

$this->Model->set('user_id', $this->Session->read('User.id'));


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-25 Thread carlosrg

You are great! :D

Ok, now I have put beforeSave() function in the model...

But I can't access from the model to $this->Session->read('User').

I'm doing well?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave()

2006-10-24 Thread Ismael S. Kafeltz

only Models has beforeSave() callback function, not the Controllers.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave question

2006-06-09 Thread stefano

Thnk you, Nate
There are 3 fileds on which the duplicate search is based, so if I
understad correctly I have to invalidate all of 3.

But they are also checked for validation like VALID_NOT_EMPTY, so I
can't taylor the error message based on the specific failure, eg "this
field can't be empty" vs "the content of this field is alredy present
in db".

Furthermore, I have to let the option to the user to add the record
anyway, even if it's duplicated, it's just an alert.

What do you think?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave question

2006-06-09 Thread nate

If there was a particular field in the model that the duplicate search
was based on, you could use Model::invalidate to invalidate that field,
and then use $html->tagErrorMsg with that field, to display the message.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: beforeSave and validationErrors array

2006-04-06 Thread nate

No, beforeSave only runs before the data actually gets saved.  If the
data doesn't validate, the data doesn't save, and beforeSave isn't
called.  If you want something that's called regardless of whether or
not the data validates, use beforeValidate.

Btw, what are you doing with $validationErrors??  All that does it hold
an array of the fields that are invalid, and you shouldn't be accessing
it directly.  If you want to invalidate a specific field, use
Model::invalidate("fieldname");


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---