Sunday, February 27, 2011

Re: Fat Models vs. App Controller

On 27 feb, 00:02, Eric Anderson <andersoneric...@gmail.com> wrote:
> Hi everyone,
>
> Just wondering when it comes to performance and any other factors you
> may deem important, what's the better option for storing functions
> that I will use among many controllers: A function in the model that I
> can then access via $this->Model->Model->function() or a function
> inside of my App Controller?

controller and model functions shouldn't overlap in functionality. The
short answer if you're asking is: always in the model.

>
> Moreover, when is it better to put a function in a model and when is
> it better to put it in the app controller?

you put controller logic in controllers, and model logic in models. If
you were to put <whatever it is you're thinking about> in your app
controller and within it call a model it's most likely the wrong thing
to be doing (asside from the fact that putting things in your app
classes is generally a bad design - use components, behaviors and
helpers) unless the controller function is controlling in some way
e.g. a couple of lines of code to collecting params and call a model
method.

>
> To put this in context, I'm investigating this for use with an
> activities feature. I track activities and then display them in feeds.
> Of course, I need to quite often save an activity, feeding it
> arguments (as well as delete an activity).

Model.

> Moreover, I need to often
> grab a feed, customized based on the arguments I feed it.

Model.

> I'm trying
> to avoid using RequestAction.

Good - because requestAction, while not the performance killer it used
to be, is still an easy way to completely miss the point of MVC.

AD

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: