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
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
$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
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
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 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
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
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,
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
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
>
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
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
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()
> {
>
>
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
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()
{
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
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
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()
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(
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
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
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
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' =>
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
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
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
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
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
>
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 {
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
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
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
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
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
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
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
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'] = $
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
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
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
: 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
-
>
> > 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
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
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
-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
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
> 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
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
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
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
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
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
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
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
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,
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
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
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
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
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 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
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
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
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
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
65 matches
Mail list logo