Martin had already answered the question quite well...
but just to add a little... in terms of good practice... think about
the usage of requestAction()...
Are you getting some data from another model and returning it to the
current controller?
In that case you are better off doing $myData = $this->CurrentModel-
>SomeOtherModel->getMyData();
You are doing two important things here. First, you are not using
requestAction() :)
secondly, you are offloading business logic of data gathering to the
model... where it really belongs.
Also, if you already have a controller with an action that does return
some data, the question is why would one "duplicate" the code in the
model as well? Actually, you are best to move that code to the model
as well, so even your controller will benefit... even if you got a
simple find(), you can wrap it in a method inside the model such as
findMeSomeCandy(); and easily call that from your controller's
find_candy():
find_candy() {
$this->set('candy', $this->Candy->findMeSomeCandy());
}
thereby also enabling to access the same method from another
controller via model relation.
Even if you need it from a completely un-related model, you can do
$candy = ClassRegistry::init('Candy')->findMeSomeCandy();
On Jan 15, 9:41 am, Martin Westin <[email protected]> wrote:
> requestAction() is a bit seductive. It can look like a simple solution
> to a lot of things but the problem (that you notice later on) is that
> is has a high "cost" in the processing overhead and in that you don't
> improve your design instead of using the "quick fix".
>
> When requestAction() is called you are effectively making a new
> request more or less as you would by refreshing the browser. You are
> starting up the router and dispatcher again. You are instantiating a
> new controller, loading new Models, querying the database. And, worst
> of all as I understand it, you are often doing a full render of an
> extra View. All this results in a very costly feature.
>
> There are times when requestAction is a good tool (the only tool?) but
> they are quite few. But without knowing your application I can't say
> if you have a justified situation or not. I always feel dutifully
> ashamed each time i use this feature which forces me to think if I
> can't get around my problem some other way :)
>
> In my current project I actually have a few but in those cases doing
> without it is too complicated for my taste and in only one instance is
> the processing overhead an issue.
>
> /Martin
>
> On Jan 15, 3:05 pm, "Mario Cesar" <[email protected]> wrote:
>
>
>
> > teknoid, why is a bad idea ???
>
> > --- p.s. It is almost always a bad idea to use requestAction() ;)
>
> > On Wed, Jan 14, 2009 at 2:29 PM, teknoid <[email protected]> wrote:
>
> > > Any params can be passed like: /controller/action/param1/param2/param3
> > > Or as named params: /controller/action/name:bob/city:paris/
> > > account:active
>
> > > to see the params in your controller pr($this->params)
>
> > > p.s. It is almost always a bad idea to use requestAction() ;)
>
> > > On Jan 14, 9:55 am, Mario Cesar <[email protected]> wrote:
> > > > hi!
> > > > i have parameters with / ex '2008/2,' '2008/1'
> > > > but the cake read only 2008
> > > > how can i pass the /???
>
> > > > i'm using
> > > > $turma = 'qqq/w';
> > > > $this->requestAction("/turmasDisciplinasHorarios/getDisciplinaTurma/
> > > > $turma/$filial/$disciplina");
>
> > > > someone can help me?- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---