Jump to content


Photo

Difference between front and application controllers?


  • Please log in to reply
2 replies to this topic

#1 devbanana

devbanana
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationI don't know, but all I can see is this computer...

Posted 26 August 2006 - 11:05 AM

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. :(
Programming in PHP since 1882. Oh wait, computers weren't around that long, huh....
Hey, while we're here, would you mind giving me some suggestions on my PHP framework?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 August 2006 - 11:21 AM

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, this may help describe it better.

#3 devbanana

devbanana
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationI don't know, but all I can see is this computer...

Posted 26 August 2006 - 11:45 AM

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, this may help describe it better.


Thanks for the link; I've read that page a couple of times already, plus other pages, like the catalog of P of EAA.

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:

<?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();
}
}

There are only a few things I wonder about with this.
  • 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.


Programming in PHP since 1882. Oh wait, computers weren't around that long, huh....
Hey, while we're here, would you mind giving me some suggestions on my PHP framework?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users