well I thought the model instance was already loaded but I can't
explain why the behaviour is not the same if I access the model A
instance.
I mean :
in my action A : there seems to be a instance of model A
in my action B (called in action A) : a different instance of model A
that is what I deduce from testing with the following code :
in model A construct method : $this->get_media_by_types = false.
in controller :
function test() {
$this->autoRender = false;
$this->Media->get_media_by_types = true;
pr("controller : : " . $this->Media->get_media_by_types);//
prints
out 1 (true)
pr('request action : ' .
$this->requestAction('/media/test2'));//
prints out nothing (false)
}
function test2() {
$this->autoRender = false;
return $this->Media->get_media_by_types;
}
I deduce that there are 2 instances of Media model created for each
action call.
this is not the case for the same test case using $this->Item->Media-
>get_media_by_types for example.
any clues ?
thaks
thomas
On Nov 4, 12:13 pm, francky06l <[EMAIL PROTECTED]> wrote:
> You request the action in an action, one instance of the modelB is
> already loaded and used. I think that quite the way I expect it to
> work, creating new instances would make some tasks very difficult to
> achieve as well as performances poor (in my opinion).
> However, you can still create explicitly a new instance of modelB in
> your action, or set some method in modelB to "init" myVar.
>
> On Nov 3, 6:26 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Hello all,
>
> > 2 models : model A - model B
> > 1 controller : controller A
> > 2 actions in controler A : action A - action B
>
> > I set a variable to false in a model B construct method :
>
> > $this->myVar = false;
>
> > I then in controller A have a main model A to which is associated
> > model B
> > in an action A I set the $this->modelA->modelB->myVar = true;
>
> > in this action I have a requestAction (for testing purposes) calling
> > action B
> > $this->requestAction('/controllerA/actionB');
>
> > if I 'pr' the $this->modelA->modelB->myVar it returns true when I
> > would expect it to return false since I would expect the instance of
> > the model to be a new one (since a new action is called).
>
> > The behaviour works as expected if I do the same on the main model.
>
> > It is like the instance of the associated model is the same for both
> > actions.
>
> > I don't know if I'm being clear but can anyone help on this ?
>
> > thanks in advance.
>
> > thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---