views:

30

answers:

2

I have a bunch of different controllers that all deal with the same basic model. For example...

  • FoobarController
  • FoobarShareController
  • FoobarTakeController
  • FoobarToolsController
  • FoobarVerifyController

They all do various things to the foobar model and I kind of wanted a better way to organize them along with other things that deal with the rest of the site like all the stuff that doesn't specifically deal with Foobar but just general site usage like the UserController, DashboardController, MainController.

My idea was to put everything into namespaces so I would have the Foobar module and the Site module. The issue with that is in the case of say the Foobar:FoobarController my paths would be foobar_foobar_path and similarly the urls would look kind of odd.

This seems less then ideal so I was wondering what the best way to do this kind of organization was instead of having everything just in one directory and thus one namespace.

+1  A: 

I think the simplest solution would just be to create a Foobar directory under controllers, and put all your foobar stuff in their. You may need to rework some routing/ajax/etc though, but this is perfectly doable and even recommended.

Zachary
A: 

Without knowing details about your various Foobar-related controllers, it would be difficult to provide advice on how to better organize them. However, you might want to ask yourself:

  • Why do you have multiple controllers in the first place?
  • Is there a good reason why these controllers cannot be combined in some way?
  • Can a shared base controller/module simplify the situation?

In general, it's best to take a DRY approach.

Logic that is repeated should be consolidated into one location.

Bennett