Code: Select all
/zfPetShop
/config
config.ini
/default
/controllers
/models
/views
/filters
/helpers
/scripts
/Zend
/extends
bootstrap.phpCode: Select all
/document_root
/images
/scripts
/styles
.htaccess
index.phpindex.php:
Code: Select all
<?php
/**
* Manually edited include path to central bootstrap.php
*/
include '/path/to/zfPetShop/bootstrap.php';Example config.ini:
Code: Select all
; zfPetShop Bootstrap Configuration
[general]
; Global settings?
encoding = "UTF-8"
logfile =
; Bootstrap settings
bootstrap.timezone = "Europe/Dublin"
bootstrap.displayerrors = 1
bootstrap.reporting = 8191
bootstrap.renderexceptions = 1
; Database settings (change around if using Zend_Db conventions)
db.host = localhost
db.name = zfpetshop
db.username = root
db.password = passwd
db.port =
db.type = pdomysql
; Other sections as neededbootstrap.php:
Code: Select all
<?php
/**
* Include path setup (assuming no facility to edit php.ini)
* Also assumed only Core ZF (or Core + copy of Incubator).
* Left out Models for now.
*/
set_include_path(
'.' . PATH_SEPARATOR
. './Zend' . PATH_SEPARATOR
. get_include_path()
);
/**
* Load configuration
*/
require 'Zend/Config/Ini.php';
$Config = new Zend_Config_Ini('./config/config.ini', 'general');
/**
* Setup the Registry
*/
require 'Zend/Registry.php';
$Registry = Zend_Registry::getInstance();
$Registry->set('Configuration', $Config);
/**
* Environmental Settings
*/
ini_set('display_errors', $Config->bootstrap->displayerrors);
error_reporting((int) $Config->bootstrap->reporting);
date_default_timezone_set($Config->bootstrap->timezone);
/**
* Detect Base URL from sanitised PHP_SELF Server variable.
* Alternatively, can of course make this a one-shot config variable.
*/
$_SERVER['PHP_SELF'] = substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - @strlen($_SERVER['PATH_INFO']));
$baseUrl = substr($_SERVER['PHP_SELF'], 0, -9); // strips the ending "index.php"
/**
* Get a Front Controller instance
*/
require 'Zend/Controller/Front.php';
$Front = Zend_Controller_Front::getInstance();
/**
* Setup the Front Controller with any application specific settings.
* Add a list of all Modularised controller directories (incl. default)
*/
$Front->throwExceptions((bool) $Config->bootstrap->renderexceptions);
$Front->setBaseUrl($baseUrl);
$Front->setControllerDirectory(array(
'default'=>'./default/controllers'
));
$Front->setParam('Registry', $Registry);
$Front->returnResponse(true);
/**
* Dispatch the Request and send the Response
*/
$Response = $Front->dispatch();
$Response->sendResponse();Just to round out the $Front->setParam() usage...
Example Zend_Controller_Action base class (./extends/zfPetShop/Controller/Action.php):
Code: Select all
<?php
class zfPetShop_Controller_Action extends Zend_Controller_Action
{
/**
* Instance of Zend_Registry passed by Zend_Controller_Front as an
* invocation argument.
*
* @var Zend_Registry
* @access protected
*/
protected $registry = null;
/**
* init() method called by Zend_Controller_Action constructor to setup
* this Action (or its subclasses). Used here to assign FC params as
* class properties.
*
* @return void
* @access public
*/
public function init()
{
if ($this->getInvokeArg('Registry') instanceof Zend_Registry) {
$this->registry = $this->getInvokeArg('Registry');
}
}
}