Re: controller action in beforeSave() ?

2007-11-19 Thread bujanga

I sometimes use code similar to the following in the beforeFilter() of
my controller:

/* function is not in byPass array and isnt being called by another function */
if(in_array($this->action,$byPass) === FALSE AND $this->action != __FUNCTION__){

}

Gary

On Nov 18, 2007 4:47 PM, Grant Cox <[EMAIL PROTECTED]> wrote:
>
> No, you cannot access ANYTHING from the controller in the model -
> that's one of the core parts of MVC.
>
> What you should do is define a new function in your model -
> register()  This can set some class variable which you can check in
> your other callbacks, eg:
>
> class YourModel extends AppModel {
>
> var $name = 'YourModel';
>
> var $is_registering = false;
>
> function register( $data )
> {
> $this->is_registering = true;
> return $this->save( $data );
> }
>
> function beforeValidate()
> {
> if ( $this->is_registering ){
> ...
> }
> }
>
> function afterSave()
> {
> if ( $this->is_registering ){
> ...
>
> }
> }
> }
>
>
>
> On Nov 18, 6:35 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > It would be great, but model doesn't have field action :/ Any other
> > ideas how to check action in model?
> >
>

--~--~-~--~~~---~--~~
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: controller action in beforeSave() ?

2007-11-18 Thread Grant Cox

No, you cannot access ANYTHING from the controller in the model -
that's one of the core parts of MVC.

What you should do is define a new function in your model -
register()  This can set some class variable which you can check in
your other callbacks, eg:

class YourModel extends AppModel {

var $name = 'YourModel';

var $is_registering = false;

function register( $data )
{
$this->is_registering = true;
return $this->save( $data );
}

function beforeValidate()
{
if ( $this->is_registering ){
...
}
}

function afterSave()
{
if ( $this->is_registering ){
...
}
}
}



On Nov 18, 6:35 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> It would be great, but model doesn't have field action :/ Any other
> ideas how to check action in model?
--~--~-~--~~~---~--~~
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: controller action in beforeSave() ?

2007-11-18 Thread [EMAIL PROTECTED]

It would be great, but model doesn't have field action :/ Any other
ideas how to check action in model?


--~--~-~--~~~---~--~~
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: controller action in beforeSave() ?

2007-11-17 Thread francky06l

Maybe if($this->action == 'activate') ..

On Nov 17, 4:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi,
> i am CakePHP newbie and I have problem. In my register user area(model
> User) I used beforeValidate, beforeSave, and afterSave functions. Body
> of this functions I need only with action: register. For other actions
> I don't need them, but when i use other actions they are used.
> I tried:
>  if (!isset($this->data['User']['id'])) {
> // some code here which is used when id is not defninied - i.e.
> actions: add, register
>
> }
>
> but i would sth. like:
>
> if (controller['action'] == 'activate') {
>  // do sth
>
> } else if ...
>
> is this possible?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



controller action in beforeSave() ?

2007-11-17 Thread [EMAIL PROTECTED]

Hi,
i am CakePHP newbie and I have problem. In my register user area(model
User) I used beforeValidate, beforeSave, and afterSave functions. Body
of this functions I need only with action: register. For other actions
I don't need them, but when i use other actions they are used.
I tried:
 if (!isset($this->data['User']['id'])) {
// some code here which is used when id is not defninied - i.e.
actions: add, register
}

but i would sth. like:

if (controller['action'] == 'activate') {
 // do sth
} else if ...


is this possible?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---