Thanks for clarifying, pytrin. I should have made that clear when I posted my structure. Here, I'll explain a little further. I0printRob, if you have any questions, I'll do my best to answer them.
I use virtual hosts within my apache configuration. If you are not familiar with virtual hosts, basically what they do is allow you to run multiple sites with one instance of apache (
for more info about virtual hosts, check out this page). This is what my virtual host looks like:
Code: Select all
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/home/example.com/htdocs/web"
<Directory "/home/example.com/htdocs/web">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
What this does is point "
http://example.com/" to my "web" directory in the structure I posted above. My apache configuration is set to use "index.html" if the user requests a directory. If there is no "index.html", it uses "index.php" and as you will notice, there is an "index.php" in my "web" directory in the structure I posted above. So when a user requests "
http://example.com/", apache serves up "web/index.php".
Here is what my "index.php" file looks like:
Code: Select all
<?php
/**
* Define the path to the application-specific code (the "app" directory)
*/
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH',
realpath(dirname(__FILE__) . '/../app'));
/**
* Create shortcuts to PHP's directory and path separators
*/
define('PS', PATH_SEPARATOR);
define('DS', DIRECTORY_SEPARATOR);
/** Zend_Application **/
require_once 'Zend/Application.php';
/** Set the default timezone **/
date_default_timezone_set("America/Los_Angeles");
/**
* The application is "bootstrapped" here. What this means is that all of the necessary
* library files, configuration, databases, etc. are included and initialized.
*/
$application = new Zend_Application(
'production',
APPLICATION_PATH . '/config/app.ini' // path to configuration file
);
/**
* And now we're off!
*/
$application->bootstrap()
->run();
As pytrin pointed out, I'm using the "
Front Controller Pattern". This means that every page is first routed through "web/index.php". This affords me many benefits. For instance, rather than having to include my library files on every page within the application, I just include them once. Within "app/Bootstrap.php" (which, as you will remember, is included from "web/index.php"). It makes my application's URLs really clean as well since all pages are routed through the index page. For instance: "
http://example.com/index.php/admin/user/create/".
Also, it allows me to build a more modular application. As you will notice, inside of the "app" directory, there is a directory called "modules". Each of these is a sort of "mini-application" within the main application. All of them can share resources, database connections, etc.
Easily the coolest benefit that comes from the front controller is something called the dispatch loop. It allows me to do all kinds of cool things. The dispatch loop is a little beyond the scope of this thread and I don't think I'd be able to properly explain it anyway. If you are interested in it, you should check out the Zend Framework Controller documentation:
http://framework.zend.com/manual/en/zen ... asics.html