webdev

Bootstrap File Example For Zend Framework

Here is some good starting file I’ve been using.
Please let me know if you think it’s good/bad/ugly/great:

<?php
/**
* Bootstrap file for zend framework
* @category zend framework tutorials
* @author Ido Green
* @see http://framework.zend.com
*/
error_reporting(E_ALL|E_STRICT);
ini_set(“display_errors”, “on”);

set_include_path(get_include_path(). PATH_SEPARATOR . ‘../library/’. PATH_SEPARATOR . ‘../application/models/’);
require_once “Zend/Loader.php”;

/**
* Required classes – if you use autoLoader you don’t need it… but it’s good to see what you might want to use.
*/
Zend_Loader::loadClass(‘Zend_Controller_Front’);
Zend_Loader::loadClass(‘Zend_Config_Ini’);
Zend_Loader::loadClass(‘Zend_View’);
Zend_Loader::loadClass(‘Zend_Session’);
Zend_Loader::loadClass(‘Zend_Log’);
Zend_Loader::loadClass(‘Zend_Controller_Request_Http’);
Zend_Loader::loadClass(‘Zend_Debug’);
Zend_Loader::loadClass(‘Zend_Auth’);
Zend_Loader::loadClass(‘Zend_Db’);
Zend_Loader::loadClass(‘Zend_Db_Table’);
Zend_Loader::loadClass(‘Zend_Registry’);

Zend_Session::start();

require_once “Zend/Session/Namespace.php”;
$consumer = new Zend_Session_Namespace(“consumer”);
Zend_Registry::set(‘consumer’, $consumer);

$config = new Zend_Config_Ini(“../application/config.ini”, “dev”); // have dev,qa,staging and prod for your own… life.

// setup database
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
Zend_Registry::set(‘config’, $config);

Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set(‘db’, $db);

require_once “Zend/Log/Writer/Stream.php”;
$writer = new Zend_Log_Writer_Stream(‘/tmp/our-project.log’);
$logger = new Zend_Log($writer);
Zend_Registry::set(‘logger’, $logger);

$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(‘../application/controllers’);
$front->setParam(‘noViewRenderer’, true);

if($config->staging) {
$front->throwExceptions(true);
}
else {
$front->throwExceptions(false);
}

$front->dispatch();
?>

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s