Ja trochę zmodyfikwoałem kod:
Może się komuś przyda

Moj index.php
date_default_timezone_set('Europe/Warsaw');
# =====>
# Define path to application directory
define('APPLICATION_PATH', BASE_PATH
. '/application'); # <=====
# =====>
# Include path
'.'
. PATH_SEPARATOR . BASE_PATH.'/library'
. PATH_SEPARATOR . APPLICATION_PATH.'/assistant'
. PATH_SEPARATOR . APPLICATION_PATH.'/db_models'
. PATH_SEPARATOR . APPLICATION_PATH.'/db_models/db_classes'
. PATH_SEPARATOR . APPLICATION_PATH.'/db_models/db_classes/generated'
);
# <=====
require_once APPLICATION_PATH."/Initializer.php";
$init = new Initializer('test');
$init->routeStartup();
Initializer.php
# Załadowanie bibliotek
require_once('Zend/Application.php');
require_once('/../functions/php.php');
require_once('Doctrine.php');
# Załadowanie pluginów
require_once('plugins/Doctrine.php');
require_once('plugins/ModelDirectory.php');
class Initializer extends Zend_Controller_Plugin_Abstract
{
protected $_config_id;
protected $_config_routes;
protected $_env;
protected $_front;
protected $_root_path;
protected $_application_path;
protected $_application_obj;
/**
* Przypisanie odpowiednich zmiennych ($_env, $_root_path, $_application_path)
* @param string $env
* @return void
*/
public function __construct($env=NULL)
{
$this->_env = $env;
$this->_root_path = BASE_PATH;
$this->_application_path = APPLICATION_PATH;
// Inicjacja aplikacji
$this->initApplication();
// Ustawienie obsługi błędów
if ($env == 'test')
{
ini_set('display_startup_errors', 1
); $this->_front->throwExceptions(true);
}
else
{
ini_set('display_startup_errors', 0
); $this->_front->throwExceptions(false);
}
}
/**
* Inicjacja plików konfiguracyjnych ini
* @return void
*/
public function initConfigs()
{
$this->_config_db = new Zend_Config_Ini('main_configs/db.ini', 'database'); // baza danych
$this->_config_routes = new Zend_Config_Ini('main_configs/routes.ini', 'routes'); // ścieżka ruteru
// Dodanie zmiennych konfiguracyjnych do rejestru
Zend_Registry::set('config_db', $this->_config_db);
Zend_Registry::set('config_routes', $this->_config_routes);
}
/**
* Inicjacja i ustawienie Aplikacji oraz Fron kontrolera
* @return void
*/
public function initApplication()
{
$this->_application_obj = new Zend_Application($this->_env);
$this->_front = Zend_Controller_Front::getInstance();
$this->_front->throwExceptions(true);
$this->_front->setModuleControllerDirectoryName('controllers');
$this->_front->addModuleDirectory($this->_application_path.'/MODULES');
}
/**
* Inicjacja Sesji
* @return void
*/
public function initSession()
{
Zend_Session::start();
new Zend_Session_Namespace('DEFAULT');
new Zend_Session_Namespace('ADMIN');
}
/**
* Inicjacja bazy danych
* @return void
*/
public function initDb()
{
$configDb = Zend_Registry::get('config_db');
$connection = Plugin_Doctrine::connect($configDb);
}
/**
* Inicjacja helperów
* @return void
*/
public function initHelpers()
{
// rejetracja domyślnego helpera
Zend_Controller_Action_HelperBroker::addPath('../models/default/helpers', 'Zend_Controller_Action_Helper');
}
/**
* Inicjacja widoków
* @return void
*/
public function initView()
{
// Bootstrap layouts
$layout = Zend_Layout::startMvc(
'layout' => 'layout',
'layoutPath' => $this->_application_path.'/MODULES/admin/layouts',
'contentKey' => 'content'
)
);
Zend_Registry::set('layout', $layout);
}
/**
* Inicjacja pluginów
* @return void
*/
public function initPlugins()
{
$this->_front->registerPlugin(new Plugin_ModelDirectory());
$this->_front->registerPlugin(new Plugin_Doctrine());
}
/**
* Inicjacja rutera
* @return void
*/
public function initRoutes()
{
$router = $this->_front->getRouter();
$config = Zend_Registry::get('config_routes');
$router->addConfig($config);
$this->_front->setRouter($router);
}
/**
* Inicjacja ścieżki do kontrolerów
* @return void
*/
public function initControllers()
{
$this->_front
->setControllerDirectory(array( 'default' => $this->_application_path.'/MODULES/default/controllers',
'admin' => $this->_application_path.'/MODULES/admin/controllers'
));
}
/**
* Start aplikacji
* @return void
*/
public function routeStartup()
{
$this->initConfigs();
$this->initRoutes();
$this->initSession();
$this->initDb();
$this->initHelpers();
$this->initView();
$this->initPlugins();
$this->initControllers();
$this->_application_obj->bootstrap();
$this->_application_obj->run();
}
}
Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
}
}
Mam jeszcze Controller.php po którym dziedziczą wszystkiem inne kontrolery z danego modułu.
abstract class Globals_Controller extends Zend_Controller_Action
{
/* -------------------------------------------------------------------------------------------------
* Metoda ta zostanie załadowana w każdym kontrolerze
* ------------------------------------------------------------------------------------------------- */
public function init()
{
$layout = Zend_Registry::get('layout');
$this->layout = $layout; //Przypisujemy $layout do właściwości głównego kontrolera $this->layout
$this->view->assign('layout', $layout); //przypisujemy $layout do szablonu
// Ustawienie strony
$this->view->doctype('XHTML1_STRICT');
$this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$this->view->headTitle()->setSeparator(' - ');
$this->view->headTitle('Panel administracyjny - asticPanel 2.0');
$this->view->headLink()->appendStylesheet($this->_request->getBaseUrl().'/media/'.$this->_getParam('module').'/css/style.css');
// Zmienne pomocnicze
$this->view->baseUrl = $this->_request->getBaseUrl();
// Załadowanie ustawień panelu administracyjnego
$module_configs = new Zend_Config_Ini('main_configs/_'.$this->_getParam('module').'.ini');
Zend_Registry::set('module_configs', $module_configs);
// Utworzenie nawigacji
$this->view->navigation = $this->navigation();
}
/* -------------------------------------------------------------------------------------------------
* Metoda ta zostanie załadowana w każdym kontrolerze
* @return Object Zend_Navigation
* ------------------------------------------------------------------------------------------------- */
public function navigation()
{
# Kategorie
# =====>
$_page =
'label' => 'Kategorie',
'action' => 'index',
'controller' => 'kategorie',
);
$_page['pages'] =
'label' => 'Dodaj kategorie',
'action' => 'dodaj',
'controller' => $_page['controller']
),
'label' => 'Lista kategorii',
'action' => 'index',
'controller' => $_page['controller']
),
);
$pages[] = $_page;
# <=====
$container = new Zend_Navigation($pages);
//pr($container->toArray());
return $container;
}
}