Directory Layout and Bootstrapping.
When someone starts with the learning of a framework, first he begins to read various articles to understand the basic rules to work with.
There are a lot of tutorials how exactly to start, and there is also an official quick start guide, but beside this there are too much advices how should you directory layout look like.
For me the following directory layout is working well. I don’t remember exactly where I’ve found it, but I think many people use it.
- application
- admin
- controllers
- models
- views
- content
- controllers
- models
- views
- layouts
- bootstrap.php
- config.ini
- library
- Zend
- public
- index.php
Almost half of the sources “how to start” recommend all of the initialization should be in index.php in the public folder. In fact all the logic of the public/private folders is that we don’t like to show anything on the web, and that’s why index.php contains only the following peace of code (it’s recommended to leave the file open from the ?> closing tag):
<?php
require '../application/bootstrap.php';
Anything else, all the initialization is in bootstrap.php:
error_reporting (E_ALL | E_STRICT);
ini_set (‘display_startup_errors’, 1);
ini_set (‘display_errors’, 1);
set_include_path (‘../library’ . PATH_SEPARATOR . get_include_path());
require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->setControllerDirectory(array(‘default’ => ‘../application/content/controllers’,
‘admin’ => ‘../application/admin/controllers’));
$front->dispatch();
We set the error reporting to be ON, which si good when you develop any application and to collect all error messages. Than add the library folder in the include path with that line of code:
set_include_path(‘../library’ . PATH_SEPARATOR . get_include_path());
Next step is to start the __autoload functionality built in Zend Framework:
require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();
Finally start the front controller which implements the singleton pattern and point to the two main directories – admin and content. I used them for administration panel and front end, but you can used as many as you application needs:
$front->setControllerDirectory(array('default' => '../application/content/controllers',
'admin' => '../application/admin/controllers'));