0

I have a cakephp2 app and the controllers are getting really big. Is there a best practice for breaking out bits of code into other functions that are not supposed to be actions?

*Sorry it has been a looong time since I did this with cakephp1.0 and back then I think I called them _functionname, which seems wrong these days.*

tereško
  • 58,060
  • 25
  • 98
  • 150
zortacon
  • 617
  • 5
  • 15

2 Answers2

1

If you controller has been growing uncontrollably, then it has accumulated domain business logic and/or presentation logic.

The solution would be to move domain logic back into model layer. Either put that functionality in AppModel classes (which might be problematic, since it uses Active Record (anti)pattern), or create higher order structures, that do not extent AppModel and instead would act as services from proper model layer implementation.

And presentation logic should go back into the views (or since you are using the Rails parody of MVC - in the view helpers).

Community
  • 1
  • 1
tereško
  • 58,060
  • 25
  • 98
  • 150
1

Use below link as reference it will serve you better.

http://www.sanisoft.com/blog/2010/05/31/cakephp-fat-models-and-skinny-controllers/

Jhanvi
  • 594
  • 3
  • 17
  • 2
    There should be newer articles on the subject. And more extensive ones. This one uses PHP4 notation and the message of whole article is "do not use query-builder in controller" – tereško Sep 26 '12 at 09:52