multi level directory design v.s single driver page design

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

multi level directory design v.s single driver page design

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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/
(#10850)
Post Reply