views:

152

answers:

2

Hi,

I am working on a website script, and currently I have a front controller, which determines what to load (e.g. what modules/extensions and controllers) based on the URI. Is this a good approach? I'm using PHP if that matters. I'm just wondering if that's not the front controller's job...

A: 

That's the front controller pattern in a nutshell and frameworks like CakePHP and Zend (I believe) do much the same thing (as does Rails, etc.).

My only thought would be whether or not you should delegate loading modules and extensions to the controllers that need or reference them as the front controller usually handles application-level actions.

ajm
+2  A: 

The method I use actually involves two controllers.

There's a Front Controller that controls the initial arrival of the request. Then there's the Page Controller that is specific for the current page (depending on the URI). The Front Controller handles loading the right Page Controller.

The Page Controller's task is to access the Model (for DB access) and other classes to compose the data for the page view.

I would say that the Front Controller should never do anything that is specific to a URI, and should remain as generic as possible so that it may be reused efficiently.

Jordy Boom