NYCPHP Meetup

[nycphp-talk] Many pages: one script

Kenneth Downs ken at secdat.com
Mon Aug 6 08:45:06 EDT 2007


Elliotte Harold wrote:
> I'm considering a simple site that I may design in PHP. PHP is 
> probably the simplest solution except for one thing: it carries a very 
> strong coupling between pages and scripts.

This may be implied by examples, but it is simply not true.  PHP, like 
any other generalized language, allows you to easily create any kind of 
structure for your code that you want and map it URLs and databases web 
services any way you want.

A common pattern is called the "universal dispatcher", where one file, 
typically index.php, accepts all queries and parses the request 
parameters and dispatches the request to some other program.

> As far as I've ever been able to tell PHP really, really, really wants 
> there to be a single primary .php file for each URL that does not 
> contain a query string (though that file may of course invoke others).

Not true.  I think that if you go this impression, the rest of your 
questions may not be valid, as they may take this false assumption as 
true.  What do you think?

>
> For the system I'm designing that simply won't work. In Java servlet 
> environments it's relatively trivial to map one servlet to an entire 
> directory structure, so that it handles all requests for all pages 
> within that hierarchy.

I don't think I can parse this statement without knowing what is in 
those "pages", why there is a servlet handling them, and what kind of 
content they are, media? interactive database table maintenance?

>
> Is there any *reasonable* way to do this in PHP? 

Again, I'm not clear on what you are trying to serve.  We probably have 
to back up to the beginning and erase the assumption that PHP has a 
one-to-one correspondence between a URL (or page) and a PHP file.  
Having erased that, we have to ask what kind of content you are trying 
to serve, then we have to look at PHP examples.

Then it would probably make sense to talk about whether to use 
mod_rewrite, talk about how PHP do its own kind of mod_rewrite, how to 
build libraries in PHP and so forth.

The hardest part is not to relate it to what you already know, such as 
Java.  That will really slow you down.



-- 
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com    www.andromeda-project.org
631-689-7200   Fax: 631-689-0527
cell: 631-379-0010




More information about the talk mailing list