• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you handle controllers for pages that are either static or do not fit the object paradigm?

Hello everyone,

I've been wondering about how to handle certain pages of my app. In particular those pages that are either static, or that don't really fit nice and neat within the objects or resources of your app.

For example, the homepage of your app? Do you create a home controller (keeping in mind that this page might need access to different models like news, comments, posts) or do you put a home (or index) function in a page controller and do it that way. I've always been a little weary of a "page" controller because it doesn't really seem to fit. But then again, building a controller for every static page doesn't necessarily seem right either.

Another thing I wonder, is do we sometimes use controllers as just namespaces instead of them actually needing to be a controller? Seems kinda inefficient to have something like a page controller that you keep adding pages to, and not needing but one function out of all those that are in the controller.

I understand very well, that when you sit down to design your application, that some objects or resources jump out at you, and they make perfect sense. Like a user for instance. Obviously you would need a user/login, user/logout, user/add, user/edit, etc. or perhaps you have a news page, and you would need news/add, news/edit, news/delete, etc. Those are easy to understand. It's the pages that don't fit into those neat examples that trouble me.

So for me, things like static pages, a home page, or even say you have a dashboard view for each different type user in your system. Would that mean you would need one dashboard controller with a method for each type of user, or for each type of user you would have a separate dashboard method?

Can anyone help me out with these pages that don't fit nicely into the object paradigm.

Not sure this is the complete answer to your question. I often create a controller called home. Then I go in to the config/routes.php file and set the default controller to home. You can load multiple models in a controller. It is not a one controller one model relationship.

Sorry after re-reading I am not sure I offered much help.

[quote author="Spicer" date="1250116049"]Sorry after re-reading I am not sure I offered much help.[/quote]

That's ok, no problem.

I've used a single controller - meta, or lobby - to service all my static pages - and they pretty much solely deliver the output of html-heavy/php-lite view snippets. I don't have a conceptual problem with some views - even those attached to controllers that talk to a lot of models, and do a lot of complex activity - being very basic, near-static pages.

I guess on a larger system you tend to move more towards a CMS approach, so things like your About-Us, Contact-Us, T&C, etc - all slowly get pushed back into the database anyway.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.