At this point you need to choose a web server to serve your content. For the purpose of this Short Cut, we chose to use the Apache web server (http://www.apache.org/). We chose it because it is easy to understand, and it's the most commonly used web server at this time.[‡]
The approach described on the following pages is rather unconventional for applications using PHP and Smarty, but it is an excellent and elegant way of implementing the MVC pattern.
Let's start with a simple filesystem layout. This filesystem layout is flexible, and you should feel free to change this example to fit your needs whenever necessary:
app - lib - smarty - pear - apis - smarty - SOAP - ... - handler - config - docroot - cache - smarty_compiled - smarty_cached - other_cache
According to this layout, the Smarty template engine will be installed in app/lib/smarty and PEAR will be installed in app/lib/pear. To run the following examples, make sure the app directory is in your PHP include path.
The following code exemplifies how to add a new path to your PHP include path:
<?php ini_set('include_path', ini_get('include_path') . ':/path/to/your/app'); ?>
A single PHP script handles all HTTP requests. This script is
responsible for choosing the right template and loading the required PHP
code. We'll call it
handler.php from now on.
There are two ways to deliver all the requests to the
handler.php script, either through Apache's
mod_rewrite module or through PHP's