Is this EVIL in cake?

10 messages Options
Embed this post
Permalink
lacenaepronta@gmail.com

Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

HI,

I'm building a component that automatically sets the locale data
member of a translate behaviour.

In the action I look for the lang param, then call the component
method.

I'd like the component to set the locale data member in order to avoid
to do that in ANY action.

Something like that:

// ------- component class
function initialize(&controller, .....) {
  // HERE I SAVE THE CONTROLLER INSTANCE
  $this->controller = $controller;
  ....
}

function doSomething() {

}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

lacenaepronta@gmail.com

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

SORRY, RETYPE AGAIN, I PRESSED THE SUBMIT BUTTON!!

HI,

I'm building a component that automatically sets the locale data
member of a translate behaviour.


In the action I look for the lang param, then call the component
method.


I'd like the component to set the locale data member in order to
avoid
to do that in ANY action.


Something like that:


// ------- component class
function initialize(&controller, .....) {
  // HERE I SAVE THE CONTROLLER INSTANCE
  $this->controller = $controller;
  ....



}


function doSomething() {
  // HERE I WANT TO ACCESS THE MODEL AND SET THE LOCALE
  $mod = $this->controller->.....
  $model->locale = $mySavedLocale;

}


IS THIS EVIL IN CAKE. IS THERE ANOTHER MVC ORIENTED METHOD?

THANKS!!






On 3 Nov, 14:44, "[hidden email]" <[hidden email]>
wrote:

> HI,
>
> I'm building a component that automatically sets the locale data
> member of a translate behaviour.
>
> In the action I look for the lang param, then call the component
> method.
>
> I'd like the component to set the locale data member in order to avoid
> to do that in ANY action.
>
> Something like that:
>
> // ------- component class
> function initialize(&controller, .....) {
>   // HERE I SAVE THE CONTROLLER INSTANCE
>   $this->controller = $controller;
>   ....
>
> }
>
> function doSomething() {
>
>
>
> }- Nascondi testo citato
>
> - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

euromark (munich)

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

there are some components that work that way
its not really evil...
in some cases this would be the appropriate way actually


On 3 Nov., 14:47, "[hidden email]" <[hidden email]>
wrote:

> SORRY, RETYPE AGAIN, I PRESSED THE SUBMIT BUTTON!!
>
> HI,
>
> I'm building a component that automatically sets the locale data
> member of a translate behaviour.
>
> In the action I look for the lang param, then call the component
> method.
>
> I'd like the component to set the locale data member in order to
> avoid
> to do that in ANY action.
>
> Something like that:
>
> // ------- component class
> function initialize(&controller, .....) {
>   // HERE I SAVE THE CONTROLLER INSTANCE
>   $this->controller = $controller;
>   ....
>
> }
>
> function doSomething() {
>   // HERE I WANT TO ACCESS THE MODEL AND SET THE LOCALE
>   $mod = $this->controller->.....
>   $model->locale = $mySavedLocale;
>
> }
>
> IS THIS EVIL IN CAKE. IS THERE ANOTHER MVC ORIENTED METHOD?
>
> THANKS!!
>
> On 3 Nov, 14:44, "[hidden email]" <[hidden email]>
> wrote:
>
> > HI,
>
> > I'm building a component that automatically sets the locale data
> > member of a translate behaviour.
>
> > In the action I look for the lang param, then call the component
> > method.
>
> > I'd like the component to set the locale data member in order to avoid
> > to do that in ANY action.
>
> > Something like that:
>
> > // ------- component class
> > function initialize(&controller, .....) {
> >   // HERE I SAVE THE CONTROLLER INSTANCE
> >   $this->controller = $controller;
> >   ....
>
> > }
>
> > function doSomething() {
>
> > }- Nascondi testo citato
>
> > - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Miles J

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

Or you could just do it in the AppController::beforeFilter().

On Nov 3, 7:52 am, "euromark (munich)" <[hidden email]>
wrote:

> there are some components that work that way
> its not really evil...
> in some cases this would be the appropriate way actually
>
> On 3 Nov., 14:47, "[hidden email]" <[hidden email]>
> wrote:
>
> > SORRY, RETYPE AGAIN, I PRESSED THE SUBMIT BUTTON!!
>
> > HI,
>
> > I'm building a component that automatically sets the locale data
> > member of a translate behaviour.
>
> > In the action I look for the lang param, then call the component
> > method.
>
> > I'd like the component to set the locale data member in order to
> > avoid
> > to do that in ANY action.
>
> > Something like that:
>
> > // ------- component class
> > function initialize(&controller, .....) {
> >   // HERE I SAVE THE CONTROLLER INSTANCE
> >   $this->controller = $controller;
> >   ....
>
> > }
>
> > function doSomething() {
> >   // HERE I WANT TO ACCESS THE MODEL AND SET THE LOCALE
> >   $mod = $this->controller->.....
> >   $model->locale = $mySavedLocale;
>
> > }
>
> > IS THIS EVIL IN CAKE. IS THERE ANOTHER MVC ORIENTED METHOD?
>
> > THANKS!!
>
> > On 3 Nov, 14:44, "[hidden email]" <[hidden email]>
> > wrote:
>
> > > HI,
>
> > > I'm building a component that automatically sets the locale data
> > > member of a translate behaviour.
>
> > > In the action I look for the lang param, then call the component
> > > method.
>
> > > I'd like the component to set the locale data member in order to avoid
> > > to do that in ANY action.
>
> > > Something like that:
>
> > > // ------- component class
> > > function initialize(&controller, .....) {
> > >   // HERE I SAVE THE CONTROLLER INSTANCE
> > >   $this->controller = $controller;
> > >   ....
>
> > > }
>
> > > function doSomething() {
>
> > > }- Nascondi testo citato
>
> > > - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

lacenaepronta@gmail.com

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

Thanks for the replies but now....HOW CAN I ACCESS THE MODEL FROM
WITHIN THE COMPONENT?




Dario



On 3 Nov, 18:35, Miles J <[hidden email]> wrote:

> Or you could just do it in the AppController::beforeFilter().
>
> On Nov 3, 7:52 am, "euromark (munich)" <[hidden email]>
> wrote:
>
>
>
> > there are some components that work that way
> > its not really evil...
> > in some cases this would be the appropriate way actually
>
> > On 3 Nov., 14:47, "[hidden email]" <[hidden email]>
> > wrote:
>
> > > SORRY, RETYPE AGAIN, I PRESSED THE SUBMIT BUTTON!!
>
> > > HI,
>
> > > I'm building a component that automatically sets the locale data
> > > member of a translate behaviour.
>
> > > In the action I look for the lang param, then call the component
> > > method.
>
> > > I'd like the component to set the locale data member in order to
> > > avoid
> > > to do that in ANY action.
>
> > > Something like that:
>
> > > // ------- component class
> > > function initialize(&controller, .....) {
> > >   // HERE I SAVE THE CONTROLLER INSTANCE
> > >   $this->controller = $controller;
> > >   ....
>
> > > }
>
> > > function doSomething() {
> > >   // HERE I WANT TO ACCESS THE MODEL AND SET THE LOCALE
> > >   $mod = $this->controller->.....
> > >   $model->locale = $mySavedLocale;
>
> > > }
>
> > > IS THIS EVIL IN CAKE. IS THERE ANOTHER MVC ORIENTED METHOD?
>
> > > THANKS!!
>
> > > On 3 Nov, 14:44, "[hidden email]" <[hidden email]>
> > > wrote:
>
> > > > HI,
>
> > > > I'm building a component that automatically sets the locale data
> > > > member of a translate behaviour.
>
> > > > In the action I look for the lang param, then call the component
> > > > method.
>
> > > > I'd like the component to set the locale data member in order to avoid
> > > > to do that in ANY action.
>
> > > > Something like that:
>
> > > > // ------- component class
> > > > function initialize(&controller, .....) {
> > > >   // HERE I SAVE THE CONTROLLER INSTANCE
> > > >   $this->controller = $controller;
> > > >   ....
>
> > > > }
>
> > > > function doSomething() {
>
> > > > }- Nascondi testo citato
>
> > > > - Mostra testo citato -- Nascondi testo citato
>
> - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

AD7six

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink



On 3 nov, 23:00, "[hidden email]" <[hidden email]>
wrote:
> Thanks for the replies but now....HOW CAN I ACCESS THE MODEL FROM
> WITHIN THE COMPONENT?

you seem to have accidentally written most of your message(s) in
capital letters.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Amit-6

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

http://filchiprogrammer.wordpress.com/2008/08/27/followthemanual/

On Nov 3, 4:32 pm, AD7six <[hidden email]> wrote:
> On 3 nov, 23:00, "[hidden email]" <[hidden email]>
> wrote:
>
> > Thanks for the replies but now....HOW CAN I ACCESS THE MODEL FROM
> > WITHIN THE COMPONENT?
>
> you seem to have accidentally written most of your message(s) in
> capital letters.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

lacenaepronta@gmail.com

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

OK, I don't know if it is the same to import and use the model or to
use the default model of the controller.

In the action I save the model like this:

$this->Group->Save

So in the component I'd like to set the locale just before the save. I
would put the code in the initialize callback of the component:

....
$this->controller->[...access the group model somehow...]->locale =
the_new_locale;
....

Sorry, but I don't know if this is the same of importing the model and
use it. Pheraps the right question is:

Does '$this->Group' works on an INSTANCE or on the CLASS??

Answer this question, and I will be a happy man.


THANKS!!







On 4 Nov, 01:45, Amit <[hidden email]> wrote:

> http://filchiprogrammer.wordpress.com/2008/08/27/followthemanual/
>
> On Nov 3, 4:32 pm, AD7six <[hidden email]> wrote:
>
>
>
> > On 3 nov, 23:00, "[hidden email]" <[hidden email]>
> > wrote:
>
> > > Thanks for the replies but now....HOW CAN I ACCESS THE MODEL FROM
> > > WITHIN THE COMPONENT?
>
> > you seem to have accidentally written most of your message(s) in
> > capital letters.- Nascondi testo citato
>
> - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

AD7six

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink



On 4 nov, 09:02, "[hidden email]" <[hidden email]>
wrote:

> OK, I don't know if it is the same to import and use the model or to
> use the default model of the controller.
>
> In the action I save the model like this:
>
> $this->Group->Save
>
> So in the component I'd like to set the locale just before the save. I
> would put the code in the initialize callback of the component:
>
> ....
> $this->controller->[...access the group model somehow...]->locale =
> the_new_locale;
> ....
>
> Sorry, but I don't know if this is the same of importing the model and
> use it. Pheraps the right question is:
>
> Does '$this->Group' works on an INSTANCE or on the CLASS??
>
> Answer this question, and I will be a happy man.
>
> THANKS!!

try

$this->controller->{$this->controller->modelClass}->locale =
'lowercase';

OR

ClassRegistry::init('ThisModel')->locale = 'lowercase';

Depending on if you want the controller's model irrespective of what
it is, or a specific model that may or may not be attached to the
controller.

hth,

AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

lacenaepronta@gmail.com

Re: Is this EVIL in cake?

Reply Threaded More More options
Print post
Permalink

Thank you, the modelClass solution is perfect!!!!


Long life to AD7six.


On 4 Nov, 09:09, AD7six <[hidden email]> wrote:

> On 4 nov, 09:02, "[hidden email]" <[hidden email]>
> wrote:
>
>
>
>
>
> > OK, I don't know if it is the same to import and use the model or to
> > use the default model of the controller.
>
> > In the action I save the model like this:
>
> > $this->Group->Save
>
> > So in the component I'd like to set the locale just before the save. I
> > would put the code in the initialize callback of the component:
>
> > ....
> > $this->controller->[...access the group model somehow...]->locale =
> > the_new_locale;
> > ....
>
> > Sorry, but I don't know if this is the same of importing the model and
> > use it. Pheraps the right question is:
>
> > Does '$this->Group' works on an INSTANCE or on the CLASS??
>
> > Answer this question, and I will be a happy man.
>
> > THANKS!!
>
> try
>
> $this->controller->{$this->controller->modelClass}->locale =
> 'lowercase';
>
> OR
>
> ClassRegistry::init('ThisModel')->locale = 'lowercase';
>
> Depending on if you want the controller's model irrespective of what
> it is, or a specific model that may or may not be attached to the
> controller.
>
> hth,
>
> AD- Nascondi testo citato
>
> - Mostra testo citato -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---