Simplifying the App(Controller/Model/Helper) concept

Published on and tagged with cakephp  ideas

Yesterday, the classes AppController, AppModel, and AppHelper were moved from the “cake” folder to the “cake/libs/controller”, “cake/libs/model”, respectively “cake/libs/view/helpers” folders (see changesets 5997 and 5998). Due to this move, my code suddenly broke as the AppHelper class wasn’t found because CakePHP still looked for it in the original folder. Creating an empty AppHelper class in my “app” folder solved the problem.

Anyway, what I realized by this incident is that the implementation of this entire concept is unnecessary “complex”. I must have been blind I didn’t saw this earlier ;-)

If you, for example, want to add some functionality to the AppController, you have either to copy the file app_controller.php from the “cake” (resp. new “cake/libs/controller”) folder to the “app” folder, or you have to create the file yourself in the “app” folder. That’s because you shouldn’t edit any files in the “cake” folder and its subfolders. This often leads to confusion: if you tell a newbie he should add something to “app/app_controller.php”, then the file is not there…

But it also makes the life of the (framework) developers a bit harder, as you have to check whether the files exist in the “app” folder, and depending on this check you then load the files either from the “app” or “cake” folder.

Sure, the aforementioned topics are no big deal, but on the other hand there are no benefits in doing it in the way it is currently done (or at least I don’t see any benefits).

A simpler solution would be to add AppController, AppModel, and AppHelper to the “app” folder by default (which is already done by the bake script when you bake a project). So those classes in the “cake” folder would be redundant and could be removed (and you could forget what I wrote above). KISS, keep it simple and stupid!

5 comments baked

  • nao

    Change today, now app_controller go to app/controllers, app_model go to app/models and app_helper go to app/view/helpers. Thanks for you ticket, I undestand why my app don’t work after read it. Ciao!

  • Larry E. Masters

    @nao,

    That is incorrect they are still located in the same directory as before, the tickets that I closed where invalid because the code was not completed.

    @cakebaker and nao,

    I suggest you both use the trunk code instead of the bleeding edge branches. Expect things to break if you are updating as soon as I commit code to the branch, the code is considered “stable” when I merge it to the trunk.

    I will refer both of you to this ticket: https://trac.cakephp.org/ticket/3595

  • Pilgrim

    Maybe this is only me but I find bake to be tedious, and I prefer to simply drop the cake folder somewhere handy and make my app folder from scratch. Bake ends up making lots of empty folders that I’ll never use. So I just go to the cake/libs folder to see what files cake intends for me to have and copy files as I need them.

  • cakebaker

    @all: Thanks for your comments!

    @Larry: Strange suggestion. Be happy there are people out there using the bleeding edge version and report issues they experience with it. But if you don’t want that I open any tickets in the future, then say it.

    @Pilgrim: Some like it, some don’t like it ;-) For me it is a handy tool to create the application skeleton with the correct permissions.

  • cakebaker » Every commit a mini-release

    […] as “invalid”. The same happened with tickets from others, too. Later PhpNut wrote in a comment: […] the tickets that I closed where invalid because the code was not […]

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License