1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <?php
/**
* Application bootstrap
*
* @uses Zend_Application_Bootstrap_Bootstrap
* @package QuickStart
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
private $_acl = null;
private $_auth = null;
private $_role = null;
public function run()
{
// Cela permet d'avoir le fichier de configuration disponible depuis n'importe ou dans l'application.
Zend_Registry::set('config', new Zend_Config($this->getOptions()));
parent::run();
}
protected function _initAutoloader() {
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'My_', // pas de namespace
'basePath' => APPLICATION_PATH,
));
return $moduleLoader;
}
protected function _initDb()
{
//on charge notre fichier de configuration
$config = new Zend_Config($this->getOptions());
//On essaye de faire une connection a la base de donnee.
try{
$db = Zend_Db::factory($config->resources->db);
//on test si la connection se fait
$db->getConnection();
}catch ( Exception $e ) {
exit( $e -> getMessage() );
}
// on stock notre dbAdapter dans le registre
Zend_Registry::set( 'db', $db );
Zend_Db_Table::setDefaultAdapter($db);
return $db;
}
protected function _initViewHelpers() {
$this->_auth = Zend_Auth::getInstance();
$this->_acl = new My_Model_Acl2();
$this->_role = $this->_auth->hasIdentity() ? $this->_auth->getStorage()->read()->usr_role : 'guest';
Zend_Registry::set('role', $this->_role);
$fc = Zend_Controller_Front::getInstance();
// Plugin qui verifie les droits
$fc->registerPlugin(new My_Plugin_Auth($this->_auth, $this->_acl));
//Plugin qui stock moduleName, controllerName, actionName
$fc->registerPlugin(new My_Plugin_LinkRegister());
// Initialisation de la vue
// Recup du Layout
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->setEncoding('UTF-8');
//Dojo
Zend_Dojo::enableView($view);
$view->dojo()
->addStyleSheetModule('dijit.themes.tundra')
->setDjConfigOption('usePlainJson', true)
->disable();
//HTML HEADER
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-type','text/html;charset=utf-8')
->appendHttpEquiv('X-UA-Compatible','IE=EmulateIE7')
->appendName('Description','Epitec');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Epitec');
$view->headScript()->appendFile('/js/jquery.js');
$view->headScript()->appendFile('/js/nav.js');
// Navigation (menus)
$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/menu.xml', 'nav');
Zend_Registry::set('test',$navContainerConfig);
$navContainer = new Zend_Navigation($navContainerConfig);
$view->navigation($navContainer);
$view->navigation()->setAcl($this->_acl);
$view->navigation()->setRole($this->_role);
//View renderer //avec ou sans, change rien
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);
return $view;
}
/**
* Initialize Translation
*
* @return Zend_Translate
*/
public function _initTranslate()
{
$translate = new Zend_Translate('array', APPLICATION_PATH . '/languages/fr.php', 'fr');
$translate->addTranslation(APPLICATION_PATH . '/languages/it.php', 'it');
$translate->setLocale('fr');
Zend_Form::setDefaultTranslator($translate);
Zend_Registry::set('Zend_Translate', $translate);
return $translate;
}
} |
Partager