Wednesday, September 30, 2009

Re: Doubt in cake php

On the other hand, to answer your question, you can always use:

ClassRegistry::init('ModelName')->find(...)

to read data from a model in a view.

I often use this approach in cached elements, that display things like
"yesterdays stats" where the read access is needed but only once per
day then cached. In an instance like that it is "helpful" to
encapsulate the whole data finding and displaying in one piece of
code.

Of course this goes against Cakes MVC approach, but it's your app and
if it works for you then great!

On Sep 29, 4:58 pm, Travis L <lele...@gmail.com> wrote:
> I don't see it as making the controller "fat", really.  It's where
> this call belongs.  I usually think of fat controllers as doing some
> of the models' heavy lifting for them.
>
> But in this case, putting the code in your controller is clearly the
> right thing to do, by Cake's MVC principles.
>
> Don't worry too much about following some abstract, arbitrary
> guidelines like "skinny controllers".  It's just a general rule of
> thumb; to me, it means to put as much data handling and managing as
> possible in the models. Use the controllers to wrangle data around and
> to handle requests (which includes access control, for most of my
> work).  The views should be limited to displaying stuff.
>
> In certain situations you might want to put more logic in the views,
> but this doesn't sound like one of them.
>
> On Sep 28, 3:15 am, John Andersen <j.andersen...@gmail.com> wrote:
>
>
>
> > It will not be much more fat, as the only thing each function used by
> > a requestAction should be doing, is to call the model and return the
> > models data.
> > Enjoy,
> >    John
>
> > On Sep 28, 12:46 pm, hunny <saurabh85maha...@gmail.com> wrote:
>
> > > On Sep 25, 10:27 am, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > > Look into the controllers method "requestAction", which allows you to
> > > > retrieve the list of clubs in a view!
> > > > Enjoy,
> > > >    John
>
> > > > On Sep 24, 11:59 am, hunny <saurabh85maha...@gmail.com> wrote:
> > [snip]
> > > Hi All,
>
> > > Thanks for your help. I was just reluctant to put the code in the
> > > controller because it makes your controller fat.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: