Page 1 of 1

multi level directory design v.s single driver page design

Posted: Tue Aug 22, 2006 1:13 am
by jimthunderbird
Hi All,
Recently I'm having a hard time thinking of this problem:

Any content-centric website will probably grow to the point that there are many sub categories. For example:
dir_1_level_1/dir_1_level_2/dir_1_level_3/...
/dir_2_level_2...
dir_2_level_2/dir_3_level_2...

I'm thinking whether I should write a php file on each level, storing all related templates there also, or I should write a driver page in the root directory and then load different templates based on the request variables, for example: driverpage.php?page=dir_1_level_1;dir_1_level_2... something like that.

Could anyone give some ideas?


With my best,
Jim

Posted: Tue Aug 22, 2006 1:25 am
by feyd
mod_rewrite it or MultiViews (.htaccess/apache conf) it. In the end it doesn't overly matter in any direction as long as the pages are written to handle varying inputs. You shouldn't have to do the mkdir()/copy() thing, that's just plain silly.

Posted: Tue Aug 22, 2006 1:28 am
by jimthunderbird
Hi,

So you mean using the driverpage and at the same time mod-rewrite those links?

If so, I guess in the future web development, we don't actually need the traditional way, making tons of sub directoires any more?


With my best,
Jim

Posted: Tue Aug 22, 2006 1:44 am
by Christopher
What you call a "driver page in the root directory" is called the Front Controller pattern. Almost every PHP framework implements this pattern these days. Most also combine mod_rewrite with what is often called a Router to decode clean URLs to parameters for the controllers.

Posted: Tue Aug 22, 2006 1:52 am
by matthijs
I think I have been looking at the same issue. There's some articles about BOOTSTRAPPING and front controller which might interest you. I have been asking about this as well in this thread.

At the moment I'm looking into using Arborints PATH_INFO class ideas to try and map url's into different controllers. I know I could use modrewrite, but I'd prefer not to. Because then each time I add a module or page to my website/application, I would have to add another rule to my htaccess file. It should be a matter of just dropping in another action/controller class in some directory. The front controller should, after recieving a request for say /myapp/widgets/show/, look if the controller class widgets exist and hand the request to that controller. Then that controller should use the action show to make the response.

If no appropriate controller and action can be found, the response should go to a general 404-response.

Posted: Tue Aug 22, 2006 2:13 am
by Christopher
You can also use PATH_INFO without mod_rewrite if you build your URLs like this:

Code: Select all

www.mysite.com/index.php/controller/action/value1/value2/