Jump to content

Archived

This topic is now archived and is closed to further replies.

devbanana

Difference between front and application controllers?

Recommended Posts

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. :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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]<?php
class FrontController
{
public function run()
{
$page = 'Home'; // Provide default
// Would normally take the default out of a configuration file
if (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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.