devbanana Posted August 26, 2006 Share Posted August 26, 2006 Hi,There seem to be several different types of controllers when it comes to the MVC pattern. I've been reading a bit about both the front controller and the application controller, but I'm failing to see what the difference is. I know the role of the front controller, but am unsure of where the application controller, if used, would play into this.Found absolutely nothing when doing a search around these forums. :( Link to comment https://forums.phpfreaks.com/topic/18710-difference-between-front-and-application-controllers/ Share on other sites More sharing options...
trq Posted August 26, 2006 Share Posted August 26, 2006 Im no OOP wizard but Im quite sure the application contoller sits further down in your application layer. Your front controller should not have direct access to business logic, rather it delegates to the application controller which would then envoke your commands and views.I cant really point you to any guides on the subject as Im reading most of my OOP stuff from a book (PHP% Objects, Patterns and Practice), however, [url=http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationController.htm]this[/url] may help describe it better. Link to comment https://forums.phpfreaks.com/topic/18710-difference-between-front-and-application-controllers/#findComment-80670 Share on other sites More sharing options...
devbanana Posted August 26, 2006 Author Share Posted August 26, 2006 [quote author=thorpe link=topic=105694.msg422309#msg422309 date=1156591296]Im no OOP wizard but Im quite sure the application contoller sits further down in your application layer. Your front controller should not have direct access to business logic, rather it delegates to the application controller which would then envoke your commands and views.I cant really point you to any guides on the subject as Im reading most of my OOP stuff from a book (PHP% Objects, Patterns and Practice), however, [url=http://www.corej2eepatterns.com/Patterns2ndEd/ApplicationController.htm]this[/url] may help describe it better.[/quote]Thanks for the link; I've read that page a couple of times already, plus other pages, like the [url=http://www.martinfowler.com/eaaCatalog/index.html]catalog of P of EAA[/url].So, it seems that the front controller would receive the request, and would perhaps parse it into some other form the application controller would understand, to map to a handler and view(s)? So something like:[code=php:0]<?phpclass FrontController{public function run(){$page = 'Home'; // Provide default// Would normally take the default out of a configuration fileif (array_key_exists('page', $_REQUEST)){$page = $_REQUEST['page'];// Do other processing to make sure it maps to a valid page}$appController = new ApplicationController($page);$appController->execute();}}[/code]There are only a few things I wonder about with this.[list][*]If I wanted to implement intercepting filters, would this be in the front, or application, controller?[*]I'm trying to think of a way to allow parameters to be passed as well. I was going to use pathinfo so that it could be like index.php/page/param1/param2, but IIS seems not to support pathinfo, and I am trying to make it work with both Apache and IIS.The only other thing I could think of is that after the page is retrieved and validated from $_REQUEST, delete $_REQUEST['page'], and pass what's left of $_REQUEST to the constructor of ApplicationController so it can get all the parameters that might be needed.I don't think it'd be a good idea for ApplicationController to use $_REQUEST specifically, unless it is passed $_REQUEST in the constructor, because I'm trying to limit access to $_REQUEST and the like to the front controller, which should handle the HTTP request.[/list] Link to comment https://forums.phpfreaks.com/topic/18710-difference-between-front-and-application-controllers/#findComment-80675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.