SitePoint Sponsor |
|
User Tag List
View Poll Results: Page Controller or Front Controller
- Voters
- 62. You may not vote on this poll
Results 1 to 25 of 48
-
Jan 19, 2006, 15:02 #1
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Page or Front Controllers, Which do you use
Hello,
I was wondering what the consensus was on the use of the Page Controller and the Front Controller.
Care to vote which option you take? What advantages or disadvantages have you found within your own context, of the choice you made. I'm not so much asking the advantages or disadvantages between these two patterns as such, but more what you've learnt by the choice you made.
For example, did you find initially you made the right choice? Or did you need to think again, etc
Lets hear your views everyone
-
Jan 19, 2006, 16:03 #2
Currently, just been using PageControllers so far.
Recently been experimenting Ruby Routes style FrontController, but looking at Rubys routes I think it may not have gone far enough, in that its limited to only using the path, but see no reason why cant do something similar with the domain too. (eg http://ren.multiuserblog.com). So back to thinking about design for abit.Last edited by Ren; Jan 20, 2006 at 05:11.
-
Jan 19, 2006, 16:06 #3
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I primarily use frontcontroller, but occasionally I'll whisk a simple pagecontroller up. Depends on the job really.
-
Jan 19, 2006, 18:13 #4
- Join Date
- Apr 2004
- Location
- FL, USA
- Posts
- 87
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Started out using Front Controllers and learned PHP only does one request at a time. Now using Page Controllers to tackle one request at a time.
Simple fool to the 3rd include.
-
Jan 19, 2006, 19:14 #5
IMO any suffiently complex app ends up having a central point where common tasks are handled, and often using page controllers ends up giving you a front controller with multiple entry points. But probably the main reason I prefer front controllers is that page controllers tend to tie your urls to your filesystem, whereas a front controller with a good routing system lets you remap your urls at will.
-
Jan 19, 2006, 19:32 #6
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Buddha443556
-
Jan 20, 2006, 04:18 #7
- Join Date
- Mar 2005
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
for very simple pages with submenus that switch the content, i'll use a page controller - no need to overcomplicate things for the sake for it. For administration or login areas, i always use a front controller.
-
Jan 20, 2006, 04:29 #8
- Join Date
- Apr 2004
- Location
- Melbourne
- Posts
- 362
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ren
http://mydomain.com/books/a-e/dark-tower/edit
or
http://mydomain.com/books/a-e/dark-tower/delete
etc. A db lookup is done on the URL to find out the ID of the item you're editing, then the appropriate action performed.
-
Jan 20, 2006, 08:28 #9
Originally Posted by Tanus
So instead of http://$user.multiuserblog.com/$year/$month/$day need something like http://$user.%baseHost/$year/$month/$day
-
Jan 21, 2006, 13:43 #10
- Join Date
- Sep 2005
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
We use a front controller for our backend systems, but we use page controllers on the frontend websites to keep it lightweight for speed...
-
Jan 21, 2006, 15:05 #11
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi.
I didn't think much of this poll when I first saw it, but now I'm genuinely surprised by the result. I was sure the page controllers would just pip the front controllers. I really am out of touch on this MVC stuff.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Jan 21, 2006, 16:31 #12
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I didn't think much of this poll when I first saw it, but now I'm genuinely surprised by the result.
-
Jan 22, 2006, 02:21 #13
- Join Date
- Aug 2005
- Location
- Santa Rosa, CA
- Posts
- 67
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I use both.
Seriously -- I use an index.php Front Controller (hidden via mod_rewrite) but my request handling code finds the appropriate Page Controller to load on the filesystem based on the URL. So, for example, a URL like:
http://www.mysite.com/category/books/view/234
Would map to a books.php file in the category folder of the site root dir, the view event would be called for the controller object, and 234 would be passed as a path parameter.
JaredWillowgarden: rapid application platform for PHP 5
xajax: fast and easy PHP Ajax library
Web software architecture blog: The Idea Basket
-
Jan 22, 2006, 10:30 #14
- Join Date
- Jan 2006
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Where is the both option?
Forgive the ignorance, but if you've got a Front Controller, don't you then (almost necessarily) have Page Controllers that the Front Controller delegates the specific request to, especially in web applications?
Just surfing around, I found this at the end of an ONLamp PHP article:
The Front Controller specifies where to go (the page to fetch for the requested URI), while a Page Controller decides what to do (the action to perform).
...
One reason to use a Front Controller with a Page Controller is to minimize the duplicated content in the extracted view pages. The Front Controller can set up common menu bars, footers, and so on, while the Page Controller will handle the specific request.
-
Jan 22, 2006, 10:59 #15
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The Front Controller can set up common menu bars, footers, and so on,
As for not having the option to select both, it is pretty much certain that when you implement a Front Controller, you'd have to implement a Page Controller anyways, but the real purpose of the poll is to find out the consensus of those who bypass the Front Controller altogether in any case
-
Jan 22, 2006, 12:17 #16
Originally Posted by dream.scape
-
Jan 23, 2006, 09:49 #17
- Join Date
- Mar 2005
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
maybe somone would be kind enough to post an example (or a link) or how a front controller delegates to page controller?
I think i might need to brush up on my concepts a bit.
-
Jan 23, 2006, 10:20 #18
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by skinny monkey
The source of the confusion is that the frontcontroller works by delegating control to ahandlercommand. And thishandlercommand is almost the same as the page in the pagecontroller pattern. The only difference is that the pagecontroller is the entrypoint of your request, while thehandlercommand gets selected by the frontcontroller (which is the entrypoint). So you might say that the pagecontroller is ahandlercommand, which can be executed directly, while in the frontcontroller pattern, thehandlercommand gets selected by the frontcontroller.
Or put in other words - The pagecontroller combines the roles ofhandlercommand andentrypointhandler, while the frontcontroller split them up into separate objects.
To further the confusion, what from one perspective may look like a pagecontroller, may also be percieved as a frontcontroller from another perspective. For example, if you see apache as part of you total application, you might argue that apache is your frontcontroller, and each php-page is ahandlercommand.
You will btw. often see the term action used in lieu ofhandlercommand.Last edited by kyberfabrikken; Jan 23, 2006 at 11:47. Reason: As 33degrees pointed out, I was even adding to the confusion with my wrong use of handler. I have corrected the terminology, so it should now match the vocabulatory if Fowler.
-
Jan 23, 2006, 10:56 #19
Originally Posted by kyberfabrikken
Originally Posted by Martin Fowler
-
Jan 23, 2006, 14:00 #20
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This object can carry out common behavior, which can be modified at runtime with decorators. The handler then dispatches to command objects for behavior particular to a request.
That given handler could I suppose, act as just about anything you'd want, such as playing a part in some sort of router...
There is nothing written in stone in that regards.
-
Jan 23, 2006, 14:32 #21
Originally Posted by Dr Livingston
I think it's best to avoid using the term handler, because in the general sense of the word, many parts of the controller hierarchy handles something, so the term is confusing.Last edited by 33degrees; Jan 23, 2006 at 14:36. Reason: Added paragraph about using the term handler
-
Jan 23, 2006, 14:36 #22
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yer, that makes more sense I suppose, but going by that then, I would think that in my case, I have therefore forgone the handler it's self. So, do we have something like this then...
Front Controller --> Handler --> Application Controller -> Action/Command;
I would think that the use of an Application Controller is optional as well
-
Jan 23, 2006, 22:55 #23
It took me a while, but I finally managed to track down an article referenced by Fowler called Objects and the Web, which talks about MVC as applied to the web. In it, they describe an architecture like:
Input Controller --> Application Controller --> Action (Command)
Where there is a single Input Controller, but multiple Application Controllers and Actions. They then go on to say that the logic contained in the action can be made a method of the Application Controller, improving encapsulation, and giving simply:
Input Controller --> Application Controller
Which happens to be my preferred architecture, and an increasingly popular one.Last edited by 33degrees; Jan 23, 2006 at 22:56. Reason: spelling...
-
Jan 24, 2006, 02:50 #24
- Join Date
- Mar 2004
- Location
- Fort Lauderdale
- Posts
- 522
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
what is the difference between Front controller and Page controller.
Is Front controller the code that calls on other code based on the task at hand? For example index.php would serve as the starting point for an application and depending on the $_REQUEST array content it would perform different actions?
index.php?mod=list&who=users
or is this a Page controller?
-
Jan 24, 2006, 09:04 #25
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:index.php?mod=list&who=users
Bookmarks