SlideShare a Scribd company logo
Zend   Bootstrap Votre serviteur : Pierre PINON
Plan I Description II Pourquoi mettre en place un Bootstrap ? III Principes, Comment ça marche ? IV Exemples V Conclusion
I Description Le Bootstrap est un fichier lancé au début de l’application qui initialise le projet. De façon générale, il permet : - D'initialiser le projet (Point d'entrée) - Définir une configuration de contexte (Dev, Preprod, Prod) - Paramétrage de Zend (Plugins, Helpers, Autoloaders, ...) - Amorcer les différents éléments (View, Layout, Form, Email, Bdd, ...)
II Pourquoi mettre en place un Bootstrap ? - Pour remplacer l'ignoble fichier  index.php  qui contient tout est n'importe quoi - Pour centraliser les paramètres internes dans un fichier de configuration (ini, xml, …) - Pour créer différents paramétrages selon le contexte - Pour faciliter la configuration des éléments avant leur utilisation et ainsi éviter les paramétrages en dur dans les contrôleurs/actions - Afin d'avoir un endroit organisé où sont initialisés les différents éléments de l'application
III Principes, Comment ça marche ? index.php Bootstrap.php - Mise en place du projet application.ini MVC config.ini
1/ index.php <?php define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array( realpath(dirname(__FILE__)) . '/../library', get_include_path() ))); require_once 'Zend/Application.php'; $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application->bootstrap()->run();
2/ Vhost Apache <VirtualHost *:80> ServerName  exemple.lan AddDefaultCharset UTF-8 DocumentRoot /var/www/exemple SetEnv APPLICATION_ENV development <Directory /var/www/exemple> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
3/ application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0   bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot; resources.frontController.moduleDirectory = APPLICATION_PATH &quot;/modules&quot; resources.frontController.plugins.error = &quot;Zend_Controller_Plugin_ErrorHandler&quot; resources.frontController.plugins.auth = &quot;Services_Plugin_Auth&quot; resources.frontController.plugins.menu = &quot;Services_Plugin_Menu&quot; resources.frontController.plugins.layout = &quot;Services_Plugin_Layout&quot; resources.frontController.plugins.jquery = &quot;Services_Plugin_JQuery&quot; resources.frontController.throwExceptions = false   autoloadernamespaces[] = &quot;Services_&quot; autoloadernamespaces[] = &quot;Doctrine_&quot; autoloadernamespaces[] = &quot;Forms_&quot;   filepaths.configs.config = APPLICATION_PATH &quot;/configs/config.ini&quot;   view.smarty.caching = 0 view.smarty.debugging = 0 view.smarty.allow_php_tag = 0   url.pel = &quot;https://secure.ogone.com/ncol/prod/orderstandard.asp&quot; [preproduction : production] url.pel = &quot;https://secure.ogone.com/ncol/test/orderstandard.asp&quot; [development : preproduction] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1   resources.frontController.throwExceptions = true   view.smarty.debugging = 1
4/ Bootstrap.php <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function __construct($application) { parent::__construct($application); $config = new Zend_Config_Ini($this->_options['filepaths']['configs']['config'], 'app'); $this->setOptions($this->getOptions() + array('app' => $config->toArray())); } protected function _initQuelqueChose() { }   protected function _initQuelqueChoseDAutre() { } }
IV Exemples 1/ Sans Zend Bootstrap - Juste un fichier index.php 2/ Avec Zend Bootstrap - Un fichier index.php - Un fichier Bootstrap.php - Un fichier application.ini
IV Exemple : Sans Bootstrap : index.php <?php // Racine du projet define('ROOT_DIR', realpath('..')); // Répertoires include set_include_path(  ROOT_DIR.PATH_SEPARATOR. ROOT_DIR.'/library'.PATH_SEPARATOR. ROOT_DIR.'/library/PEAR'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes'.PATH_SEPARATOR. ROOT_DIR.'/project/Modules'.PATH_SEPARATOR. ROOT_DIR.'/project'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes/Doctrine/models'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes/Doctrine/models/generated'.PATH_SEPARATOR. get_include_path()); // Initialisation de la session $exception = null; try { require_once('Zend/Session.php'); Zend_Session::start(); } catch (Exception $exception) { session_start(); } // Initialisation de la gestion d'erreurs require_once('NCore/Exception.php'); NCore_Exception_Manager::setUncatchedExceptionCallback('displayUncatchedException'); if ($exception !== null) Ncore_Exception_Manager::process($exception); // Initialisation de l'autoloader require_once('NCore/Autoloader.php'); require_once('Loader.php'); $autoloader = NCore_Autoloader::getInstance(); $autoloader->addLoader(array('Loader', 'formLoader')); $autoloader->addLoader(array('Doctrine_Core', 'autoload')); // Initialisation de la configuration NCore_Config_Cache::setPath(ROOT_DIR . '/temp/cache/config/.'); NCore_Config_Cache::enable(); NCore_Config::setConfigDir(ROOT_DIR . '/config') ; // Initialisation de Smarty require_once('NCore/Smarty.php'); Ncore_Smarty::setDirectoryCompile(ROOT_DIR.'/temp/templates_c'); NCore_Smarty::addDirectoryPlugin('Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Filigrane/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Version/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Xiti/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('SmartyPlugin/'); Ncore_Smarty::addDirectoryPlugin('NCore/Form/Smarty/plugins/'); // Initialisation de la vue Smarty, et du rendu final via Smarty require_once('NCore/Smarty/View.php'); require_once('NCore/Smarty/Decorator/Response.php'); NCore_Smarty_View::initViewRenderer(); NCore_Controller_Front::getInstance()->setResponse(new NCore_Smarty_Decorator_Response(ROOT_DIR . '/project/Modules/default/views/main.tpl')); // Parametrage du Front Controller require_once('NCore/Controller/Front.php'); require_once('ZendPlugin/Init.php'); require_once('ZendPlugin/Menu.php'); $manager = NCore_Doctrine::connect(); $manager->setCharset('utf8'); NCore_Form::enableJQuery(); NCore_Form::setDefaultDecorators( array( array('ViewScript', array('viewScript' => 'default|form.tpl')), array('AjaxJQValidator') )); NCore_Form::setDefaultElementDecorators( array( array('ViewScript', array('viewScript' => 'default|formElementVertical.tpl')), )); Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view->addHelperPath('ZendHelperView', 'ZendHelperView'); Zend_Controller_Action_HelperBroker::addPath('ZendHelperCtrl', 'ZendHelperCtrl'); Zend_Controller_Action_HelperBroker::getStaticHelper('Auth'); NCore_Controller_Front::getInstance() ->throwExceptions(false) ->setModuleControllerDirectoryName('ctrl') ->addModuleDirectory(ROOT_DIR . '/project/Modules/') ->registerPlugin(new ZendPlugin_Init()) ->registerPlugin(new ZendPlugin_Menu()) ->registerPlugin(new ZendPlugin_Auth()) ->setBaseUrl() ->dispatch();
IV Exemple : Avec Bootstrap : Bootstrap.php  <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function __construct($application) { parent::__construct($application);   $config = new Zend_Config_Ini($this->_options['filepaths']['configs']['config'], 'app'); $this->setOptions($this->getOptions() + array('app' => $config->toArray()));   Zend_Registry::set('configs', $this->getOptions()); }   protected function _initView() { include_once &quot;Smarty-3.0.6/libs/Smarty.class.php&quot;;   $view = new Services_View($this->_options['paths']['modules'], $this->_options['paths']['smarty']['temp'], $this->_options['view']['smarty']); $view->getEngine()->addPluginsDir($this->_options['paths']['smarty']['plugins']); $view->doctype('XHTML1_STRICT');   $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); $viewRenderer->setView($view) ->setViewSuffix('tpl') ->setViewBasePathSpec($this->_options['paths']['modules']) ->setViewScriptPathSpec('/:module/views/scripts/:controller/:action.:suffix') ->setViewScriptPathNoControllerSpec(':action.:suffix'); }   protected function _initZendx() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;   $view->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper'); $view->jQuery()->setRenderMode(ZendX_JQuery::RENDER_JAVASCRIPT |  ZendX_JQuery::RENDER_JQUERY_ON_LOAD); //Tout sauf l'affichage des styles et scripts }   protected function _initLayout() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;   $inflector = new Zend_Filter_Inflector(':script.:suffix'); $inflector->addRules(array(':script' => array('Word_CamelCaseToDash', 'StringToLower'), 'suffix'  => 'tpl'));   Zend_Layout::startMvc(array('layout' => $this->_options['filepaths']['form']['layout'], 'view' => $view, 'contentKey' => 'content', 'inflector' => $inflector)); } protected function _initForm() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $view->addHelperPath($this->_options['paths']['form']['helpers'], 'Services_Form_Helper');   Services_Form::addDefaultPrefixPath('Services_Form_Element',  $this->_options['paths']['form']['elements'],  'element'); Services_Form::addDefaultPrefixPath('Services_Form_Decorator',  $this->_options['paths']['form']['decorators'], 'decorator'); Services_Form::addDefaultElementPrefixPath('Services_Form_Validate',  $this->_options['paths']['form']['validates'],  'validate'); Services_Form::addDefaultElementPrefixPath('Services_Form_Decorator',  $this->_options['paths']['form']['decorators'], 'decorator'); Services_Form::addDefaultElementPrefixPath('Services_Form_Filter',  $this->_options['paths']['form']['filters'], 'filter'); Services_Form::setTplForm($this->_options['filepaths']['form']['tplForm']); Services_Form::setTplElement($this->_options['filepaths']['form']['tplElement']); }   protected function _initHelpers() { //Helper d'action foreach ($this->_options['paths']['helpers']['actions'] as $module => $path) Zend_Controller_Action_HelperBroker::addPath($path, 'Modules_' . ucfirst($module) . '_Controllers_Helpers'); Zend_Controller_Action_HelperBroker::getStaticHelper('Auth'); Zend_Controller_Action_HelperBroker::getStaticHelper('Configs');   //Helper de vue $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $view->addHelperPath($this->_options['paths']['view']['helpers'], 'Services_View_Helper'); foreach ($this->_options['paths']['helpers']['views'] as $module => $path) $view->addHelperPath($path, 'Modules_' . ucfirst($module) . '_Views_Helpers'); }   protected function _initDoctrine() { Zend_Loader_Autoloader::getInstance()->pushAutoloader(array('Doctrine_Core','modelsAutoload'));   Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); Doctrine_Core::loadModels($this->_options['paths']['doctrine']['models_path']);   $connection = Doctrine_Manager::connection($this->_options['app']['doctrine']['dsn']); $connection->setCollate($this->_options['app']['doctrine']['collate']); $connection->setCharset($this->_options['app']['doctrine']['charset']); }   protected function _initEmail() { Services_EmailExad::setOptions($this->_options['app']['email']); Services_EmailExad::setPathTpls('default/views/scripts/emails'); }   protected function _initEnums() { Services_Enums::setEnumsFile($this->_options['filepaths']['configs']['enums'], 'enums'); } }
V Conclusion 1/ Sans Zend Bootstrap - Plus simple à mettre en place - Tout centralisé dans un seul fichier index.php - Difficile à maintenir 2/ Avec Zend Bootstrap - Plus d'organisation - Une initialisation/configuration flexible (contextes) et harmonieuse (Une place pour chaque chose et chaque chose à sa place [ Samuel Smiles] ) - Un peu plus de travail en début de projet (Si peu...)
Des questions ?

More Related Content

PDF
Curso Symfony - Clase 5
PDF
Silex al límite
PDF
Add tag shortcode
PDF
DeSymfony 2012: Symfony internals
PDF
Introducción a Bolt
PDF
PHP Profiling
PDF
Testování prakticky
PDF
Introduction à Marionette
Curso Symfony - Clase 5
Silex al límite
Add tag shortcode
DeSymfony 2012: Symfony internals
Introducción a Bolt
PHP Profiling
Testování prakticky
Introduction à Marionette

What's hot (12)

PPTX
12.doctrine view data
PDF
Java script.trend(spec)
PPT
Symfony: Domesticando los Formularios
ODP
Barcamp
DOCX
Simular un next del recordset en php de forma rudimentaria
PDF
HTTP Interceptors com AngularJS
PPTX
Silex. Микрофреймворк для микроприложений
PPTX
Modelo Php
PDF
Practical JavaScript Programming - Session 2/8
DOCX
Php codigos interfaces fredy guzman cusihunca
PDF
Front-end en WordPress
PDF
Configurar con spring un api no basado en spring
12.doctrine view data
Java script.trend(spec)
Symfony: Domesticando los Formularios
Barcamp
Simular un next del recordset en php de forma rudimentaria
HTTP Interceptors com AngularJS
Silex. Микрофреймворк для микроприложений
Modelo Php
Practical JavaScript Programming - Session 2/8
Php codigos interfaces fredy guzman cusihunca
Front-end en WordPress
Configurar con spring un api no basado en spring
Ad

More from neuros (20)

PDF
Solution pour un Réseau Social d'Entreprise (RSE)
PDF
Le service workers
PDF
Proteger votre vie privee sur internet
PDF
Le pouvoir d'être Visible ou Invisible sur Internet
PDF
Vos projets web sur les plateformes ouvertes
PDF
Livre Drupal avance, un CMS pour développeurs
PDF
Http2 les impacts dans le web
PDF
Php 7 Think php7
PDF
RGAA 3 dans un Web Accessible
PDF
Les effets de la loi Hamon
PDF
La sécurité et php
PPTX
Les protocoles temps réels
PDF
Vectoriel et 3d en html5 - Animation newschool (partie 2)
PDF
Améliorer les performances SQL
PDF
Newschool partie1 methode HTML5
PDF
Integrons en mode continu
PDF
Effectuer des tests modernes pour drupal
PDF
Integration Drupal systemes d'informations
PDF
La maitrise des contenus hors internet
PDF
La mémoire et PHP
Solution pour un Réseau Social d'Entreprise (RSE)
Le service workers
Proteger votre vie privee sur internet
Le pouvoir d'être Visible ou Invisible sur Internet
Vos projets web sur les plateformes ouvertes
Livre Drupal avance, un CMS pour développeurs
Http2 les impacts dans le web
Php 7 Think php7
RGAA 3 dans un Web Accessible
Les effets de la loi Hamon
La sécurité et php
Les protocoles temps réels
Vectoriel et 3d en html5 - Animation newschool (partie 2)
Améliorer les performances SQL
Newschool partie1 methode HTML5
Integrons en mode continu
Effectuer des tests modernes pour drupal
Integration Drupal systemes d'informations
La maitrise des contenus hors internet
La mémoire et PHP
Ad

Zend bootstrap

  • 1. Zend Bootstrap Votre serviteur : Pierre PINON
  • 2. Plan I Description II Pourquoi mettre en place un Bootstrap ? III Principes, Comment ça marche ? IV Exemples V Conclusion
  • 3. I Description Le Bootstrap est un fichier lancé au début de l’application qui initialise le projet. De façon générale, il permet : - D'initialiser le projet (Point d'entrée) - Définir une configuration de contexte (Dev, Preprod, Prod) - Paramétrage de Zend (Plugins, Helpers, Autoloaders, ...) - Amorcer les différents éléments (View, Layout, Form, Email, Bdd, ...)
  • 4. II Pourquoi mettre en place un Bootstrap ? - Pour remplacer l'ignoble fichier index.php qui contient tout est n'importe quoi - Pour centraliser les paramètres internes dans un fichier de configuration (ini, xml, …) - Pour créer différents paramétrages selon le contexte - Pour faciliter la configuration des éléments avant leur utilisation et ainsi éviter les paramétrages en dur dans les contrôleurs/actions - Afin d'avoir un endroit organisé où sont initialisés les différents éléments de l'application
  • 5. III Principes, Comment ça marche ? index.php Bootstrap.php - Mise en place du projet application.ini MVC config.ini
  • 6. 1/ index.php <?php define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array( realpath(dirname(__FILE__)) . '/../library', get_include_path() ))); require_once 'Zend/Application.php'; $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application->bootstrap()->run();
  • 7. 2/ Vhost Apache <VirtualHost *:80> ServerName exemple.lan AddDefaultCharset UTF-8 DocumentRoot /var/www/exemple SetEnv APPLICATION_ENV development <Directory /var/www/exemple> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
  • 8. 3/ application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot; resources.frontController.moduleDirectory = APPLICATION_PATH &quot;/modules&quot; resources.frontController.plugins.error = &quot;Zend_Controller_Plugin_ErrorHandler&quot; resources.frontController.plugins.auth = &quot;Services_Plugin_Auth&quot; resources.frontController.plugins.menu = &quot;Services_Plugin_Menu&quot; resources.frontController.plugins.layout = &quot;Services_Plugin_Layout&quot; resources.frontController.plugins.jquery = &quot;Services_Plugin_JQuery&quot; resources.frontController.throwExceptions = false autoloadernamespaces[] = &quot;Services_&quot; autoloadernamespaces[] = &quot;Doctrine_&quot; autoloadernamespaces[] = &quot;Forms_&quot; filepaths.configs.config = APPLICATION_PATH &quot;/configs/config.ini&quot; view.smarty.caching = 0 view.smarty.debugging = 0 view.smarty.allow_php_tag = 0 url.pel = &quot;https://secure.ogone.com/ncol/prod/orderstandard.asp&quot; [preproduction : production] url.pel = &quot;https://secure.ogone.com/ncol/test/orderstandard.asp&quot; [development : preproduction] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.throwExceptions = true view.smarty.debugging = 1
  • 9. 4/ Bootstrap.php <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function __construct($application) { parent::__construct($application); $config = new Zend_Config_Ini($this->_options['filepaths']['configs']['config'], 'app'); $this->setOptions($this->getOptions() + array('app' => $config->toArray())); } protected function _initQuelqueChose() { } protected function _initQuelqueChoseDAutre() { } }
  • 10. IV Exemples 1/ Sans Zend Bootstrap - Juste un fichier index.php 2/ Avec Zend Bootstrap - Un fichier index.php - Un fichier Bootstrap.php - Un fichier application.ini
  • 11. IV Exemple : Sans Bootstrap : index.php <?php // Racine du projet define('ROOT_DIR', realpath('..')); // Répertoires include set_include_path( ROOT_DIR.PATH_SEPARATOR. ROOT_DIR.'/library'.PATH_SEPARATOR. ROOT_DIR.'/library/PEAR'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes'.PATH_SEPARATOR. ROOT_DIR.'/project/Modules'.PATH_SEPARATOR. ROOT_DIR.'/project'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes/Doctrine/models'.PATH_SEPARATOR. ROOT_DIR.'/project/Classes/Doctrine/models/generated'.PATH_SEPARATOR. get_include_path()); // Initialisation de la session $exception = null; try { require_once('Zend/Session.php'); Zend_Session::start(); } catch (Exception $exception) { session_start(); } // Initialisation de la gestion d'erreurs require_once('NCore/Exception.php'); NCore_Exception_Manager::setUncatchedExceptionCallback('displayUncatchedException'); if ($exception !== null) Ncore_Exception_Manager::process($exception); // Initialisation de l'autoloader require_once('NCore/Autoloader.php'); require_once('Loader.php'); $autoloader = NCore_Autoloader::getInstance(); $autoloader->addLoader(array('Loader', 'formLoader')); $autoloader->addLoader(array('Doctrine_Core', 'autoload')); // Initialisation de la configuration NCore_Config_Cache::setPath(ROOT_DIR . '/temp/cache/config/.'); NCore_Config_Cache::enable(); NCore_Config::setConfigDir(ROOT_DIR . '/config') ; // Initialisation de Smarty require_once('NCore/Smarty.php'); Ncore_Smarty::setDirectoryCompile(ROOT_DIR.'/temp/templates_c'); NCore_Smarty::addDirectoryPlugin('Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Filigrane/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Version/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('NCore/Xiti/Smarty/plugins/'); NCore_Smarty::addDirectoryPlugin('SmartyPlugin/'); Ncore_Smarty::addDirectoryPlugin('NCore/Form/Smarty/plugins/'); // Initialisation de la vue Smarty, et du rendu final via Smarty require_once('NCore/Smarty/View.php'); require_once('NCore/Smarty/Decorator/Response.php'); NCore_Smarty_View::initViewRenderer(); NCore_Controller_Front::getInstance()->setResponse(new NCore_Smarty_Decorator_Response(ROOT_DIR . '/project/Modules/default/views/main.tpl')); // Parametrage du Front Controller require_once('NCore/Controller/Front.php'); require_once('ZendPlugin/Init.php'); require_once('ZendPlugin/Menu.php'); $manager = NCore_Doctrine::connect(); $manager->setCharset('utf8'); NCore_Form::enableJQuery(); NCore_Form::setDefaultDecorators( array( array('ViewScript', array('viewScript' => 'default|form.tpl')), array('AjaxJQValidator') )); NCore_Form::setDefaultElementDecorators( array( array('ViewScript', array('viewScript' => 'default|formElementVertical.tpl')), )); Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view->addHelperPath('ZendHelperView', 'ZendHelperView'); Zend_Controller_Action_HelperBroker::addPath('ZendHelperCtrl', 'ZendHelperCtrl'); Zend_Controller_Action_HelperBroker::getStaticHelper('Auth'); NCore_Controller_Front::getInstance() ->throwExceptions(false) ->setModuleControllerDirectoryName('ctrl') ->addModuleDirectory(ROOT_DIR . '/project/Modules/') ->registerPlugin(new ZendPlugin_Init()) ->registerPlugin(new ZendPlugin_Menu()) ->registerPlugin(new ZendPlugin_Auth()) ->setBaseUrl() ->dispatch();
  • 12. IV Exemple : Avec Bootstrap : Bootstrap.php <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function __construct($application) { parent::__construct($application); $config = new Zend_Config_Ini($this->_options['filepaths']['configs']['config'], 'app'); $this->setOptions($this->getOptions() + array('app' => $config->toArray())); Zend_Registry::set('configs', $this->getOptions()); } protected function _initView() { include_once &quot;Smarty-3.0.6/libs/Smarty.class.php&quot;; $view = new Services_View($this->_options['paths']['modules'], $this->_options['paths']['smarty']['temp'], $this->_options['view']['smarty']); $view->getEngine()->addPluginsDir($this->_options['paths']['smarty']['plugins']); $view->doctype('XHTML1_STRICT'); $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); $viewRenderer->setView($view) ->setViewSuffix('tpl') ->setViewBasePathSpec($this->_options['paths']['modules']) ->setViewScriptPathSpec('/:module/views/scripts/:controller/:action.:suffix') ->setViewScriptPathNoControllerSpec(':action.:suffix'); } protected function _initZendx() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $view->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper'); $view->jQuery()->setRenderMode(ZendX_JQuery::RENDER_JAVASCRIPT | ZendX_JQuery::RENDER_JQUERY_ON_LOAD); //Tout sauf l'affichage des styles et scripts } protected function _initLayout() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $inflector = new Zend_Filter_Inflector(':script.:suffix'); $inflector->addRules(array(':script' => array('Word_CamelCaseToDash', 'StringToLower'), 'suffix' => 'tpl')); Zend_Layout::startMvc(array('layout' => $this->_options['filepaths']['form']['layout'], 'view' => $view, 'contentKey' => 'content', 'inflector' => $inflector)); } protected function _initForm() { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $view->addHelperPath($this->_options['paths']['form']['helpers'], 'Services_Form_Helper'); Services_Form::addDefaultPrefixPath('Services_Form_Element', $this->_options['paths']['form']['elements'], 'element'); Services_Form::addDefaultPrefixPath('Services_Form_Decorator', $this->_options['paths']['form']['decorators'], 'decorator'); Services_Form::addDefaultElementPrefixPath('Services_Form_Validate', $this->_options['paths']['form']['validates'], 'validate'); Services_Form::addDefaultElementPrefixPath('Services_Form_Decorator', $this->_options['paths']['form']['decorators'], 'decorator'); Services_Form::addDefaultElementPrefixPath('Services_Form_Filter', $this->_options['paths']['form']['filters'], 'filter'); Services_Form::setTplForm($this->_options['filepaths']['form']['tplForm']); Services_Form::setTplElement($this->_options['filepaths']['form']['tplElement']); } protected function _initHelpers() { //Helper d'action foreach ($this->_options['paths']['helpers']['actions'] as $module => $path) Zend_Controller_Action_HelperBroker::addPath($path, 'Modules_' . ucfirst($module) . '_Controllers_Helpers'); Zend_Controller_Action_HelperBroker::getStaticHelper('Auth'); Zend_Controller_Action_HelperBroker::getStaticHelper('Configs'); //Helper de vue $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view; $view->addHelperPath($this->_options['paths']['view']['helpers'], 'Services_View_Helper'); foreach ($this->_options['paths']['helpers']['views'] as $module => $path) $view->addHelperPath($path, 'Modules_' . ucfirst($module) . '_Views_Helpers'); } protected function _initDoctrine() { Zend_Loader_Autoloader::getInstance()->pushAutoloader(array('Doctrine_Core','modelsAutoload')); Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); Doctrine_Core::loadModels($this->_options['paths']['doctrine']['models_path']); $connection = Doctrine_Manager::connection($this->_options['app']['doctrine']['dsn']); $connection->setCollate($this->_options['app']['doctrine']['collate']); $connection->setCharset($this->_options['app']['doctrine']['charset']); } protected function _initEmail() { Services_EmailExad::setOptions($this->_options['app']['email']); Services_EmailExad::setPathTpls('default/views/scripts/emails'); } protected function _initEnums() { Services_Enums::setEnumsFile($this->_options['filepaths']['configs']['enums'], 'enums'); } }
  • 13. V Conclusion 1/ Sans Zend Bootstrap - Plus simple à mettre en place - Tout centralisé dans un seul fichier index.php - Difficile à maintenir 2/ Avec Zend Bootstrap - Plus d'organisation - Une initialisation/configuration flexible (contextes) et harmonieuse (Une place pour chaque chose et chaque chose à sa place [ Samuel Smiles] ) - Un peu plus de travail en début de projet (Si peu...)