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://t

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

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 fr

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 i

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

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

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

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,

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 a

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 >

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

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 d

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() >          { > >        

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

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() {

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

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

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()

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(

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 Co

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['ArvcPro

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'] ['cri

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' =>

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_m

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

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 reconfigur

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 be

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 >

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 {

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.simon

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

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 bel

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

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 mode

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

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 AppControll

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'] = $

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 no

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 h

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
hey 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

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
: 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 b

Re: beforeSave problem (1.2)

2007-02-13 Thread nate
- > > > 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 > > > -Me

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
TECTED] 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 tel

Re: beforeSave problem (1.2)

2007-02-13 Thread the_woodsman
on 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

Re: beforeSave problem (1.2)

2007-02-13 Thread nate
-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

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
viado 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

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 my

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
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

RE: beforeSave problem (1.2)

2007-02-13 Thread Mariano Iglesias
nal- 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

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

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

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

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_recurs

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 na

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,

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 "Cak

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

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

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

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')); --~--~-~--~~~---~--~~

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

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 fr

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

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

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