Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


View Poll Results: Design Method
Every page has a controller and it's own actions 2 50.00%
Index controller with actions for each page 1 25.00%
Other (Please explain) 1 25.00%
Voters: 4. You may not vote on this poll

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-25-2008, 07:50 PM
Junior Member
 
Join Date: Sep 2008
Posts: 3
Default Best Practices for File Layout

Just out of curiosity I was wondering how everyone else sets up their pages.

Do you setup a new controller for every page and then actions for that page are within it's own controller or do you setup an index controller and then make an action for each new page?

Right now I have an index controller with an action for each new page and I'm thinking about switching to each page having it's own controller as I notice this is how Zend Framework is designed.

So how do you all do it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-26-2008, 12:45 PM
wrs's Avatar
wrs wrs is offline
Member
 
Join Date: Sep 2008
Posts: 42
Default

I think its fair to say the layout of your application is for your own benefit, although having too many actions in one controller might be ineffecient especially if only a few are available to common visitors ( unauthenticated ).

Eg, if your application is only responsible for displaying information from an external source ( like an RSS feed ) then one controller and a handful of actions should suffice.

But as your application grows, perhaps you wish to allow registration/logins etc and permit certain users more control over the information displayed ,then it makes sense to begin seperating this logic in to appropriate controllers/modules.

This kind of query suggests you arn't too sure of the real scope of your application. You may find it helpful to sit down with a pen and paper and think over the various components of your app and how they relate to each other. Doing this at a later date could cause you more confusion than is needed.

Last edited by wrs : 09-26-2008 at 12:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-26-2008, 02:03 PM
Junior Member
 
Join Date: Sep 2008
Posts: 3
Default

Quote:
Originally Posted by wrs View Post
I think its fair to say the layout of your application is for your own benefit, although having too many actions in one controller might be ineffecient especially if only a few are available to common visitors ( unauthenticated ).

Eg, if your application is only responsible for displaying information from an external source ( like an RSS feed ) then one controller and a handful of actions should suffice.

But as your application grows, perhaps you wish to allow registration/logins etc and permit certain users more control over the information displayed ,then it makes sense to begin seperating this logic in to appropriate controllers/modules.

This kind of query suggests you arn't too sure of the real scope of your application. You may find it helpful to sit down with a pen and paper and think over the various components of your app and how they relate to each other. Doing this at a later date could cause you more confusion than is needed.
The major reason for me switching is due to the fact that the website being built is a learning site for me. It's not really for my visitors. So I figured in order for me to fully be able to learn the approaches of OOP and Zend Framework that this change is needed. Just didn't know if that's how most people design their applications as well.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-04-2008, 01:25 AM
phpoet's Avatar
Junior Member
 
Join Date: Sep 2008
Posts: 10
Default

In general, I have a controller for each logical group of pages. For example, if I have an admin area I'll have an Admin controller that handles all the pages in the admin area. If the site is an ecommerce site I'll have a controller for the checkout process that operates behind SSL and another controller for the "shopping" pages that don't need to be behind SSL. One controller for the entire site is probably a bad idea unless it's a small site. But one controller per page is most likely overkill.

I am putting together an very in depth tutorial/screencast on how to install, organize, and develop a web application on top of the Zend Framework at TheWeb Lessons.com It will be a huge help for anyone wanting to get a comprehensive overview of some Zend Framework best practices. The lesson will include the source code for a fully functional web app, a screencast explaining everything, and a PDF book. If you sign up at the site I'll email you when the lesson is ready.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-10-2008, 04:06 PM
Junior Member
 
Join Date: Jul 2008
Posts: 8
Default

In general, it's probably a good idea to start by thinking critically about your domain (cf domain-driven design, a great book), and think about page layout later.

In terms of using the ZF MVC architecture, I think the main advantage to grouping actions inside one controller is that you can use an action helper to add functionality to all actions inside the controller. For example: suppose you have an admin area within an otherwise public site. There's no need to check authentication/acl unless you're in the admin area, so the ideal way to implement this is by creating an action helper that's triggered by the preDispatch() hook.

In contrast, if your whole site's functionality differs when someone's logged in, for example, a forums website where the ability to comment is enabled/disabled, then you'd want to create a front controller plugin, which would check credentials for every action in every controller.

There are a couple good articles on these topics on DevZone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-10-2008, 04:08 PM
Junior Member
 
Join Date: Jul 2008
Posts: 8
Default

Also, remember that one action != one page in general, since you can use partials to update only certain parts of the page, leaving other parts static. This is how you can do widgets in ZF
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-11-2008, 11:52 PM
Junior Member
 
Join Date: Sep 2008
Posts: 15
Default

I chose others.

It just depends on the analisys you make (OO i might add, using UML probably).
I have one controller for each object, several actions for each cotroller (=object), and 1 or more outputs for each action, just depends on the logic.

So my suggestion is, model it right and you will get the answer.
Some objects might be controllers, others might be models (MVC speaking).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:51 PM.