PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Using Zend_Tool

The quickest way to start using Zend_Application is to use Zend_Tool to generate your project. This will also create your Bootstrap class and file.

To create a project, execute the zf command (on *nix systems):

% zf create project newproject

Or the Windows zf.bat command:

C:> zf.bat create project newproject

Both will create a project structure that looks like the following:

newproject
|-- application
|   |-- Bootstrap.php
|   |-- configs
|   |   `-- application.ini
|   |-- controllers
|   |   |-- ErrorController.php
|   |   `-- IndexController.php
|   |-- models
|   `-- views
|       |-- helpers
|       `-- scripts
|           |-- error
|           |   `-- error.phtml
|           `-- index
|               `-- index.phtml
|-- library
|-- public
|   `-- index.php
`-- tests
    |-- application
    |   `-- bootstrap.php
    |-- library
    |   `-- bootstrap.php
    `-- phpunit.xml

In the above diagram, your bootstrap is in newproject/application/Bootstrap.php, and looks like the following at first:

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
}

You'll also note that a configuration file, newproject/application/configs/application.ini, is created. It has the following contents:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

All settings in this configuration file are for use with Zend_Application and your bootstrap.

Another file of interest is the newproject/public/index.php file, which invokes Zend_Application and dispatches it.

<?php
// Define path to application directory
defined('APPLICATION_PATH')
    || 
define('APPLICATION_PATH',
              
realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || 
define('APPLICATION_ENV',
              (
getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
                                         : 
'production'));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    
APPLICATION_ENV,
    
APPLICATION_PATH '/configs/application.ini'
);
$application->bootstrap()
            ->
run();

To continue the quick start, please skip to the Resources section.

Zend Framework