initialize(); } /** * Generates needed Objects and initializes the static vars * * @return void */ public function initialize ($server = false) { // init the logger $this->init_log($server); // read the config $this->init_config(); // generate db connection $this->init_db($server); // init translate $this->init_translate(); // a helper $this->helper = Zm_Helper::getInstance(); // init the smarty view $this->init_view(); // the front $this->init_front($server); // for routes $this->init_router(); } /** * This method loads the config.xml * */ public function init_config () { // read the config $this->config = $config = new Zend_Config_Xml('../application/modules/default/config/config.xml'); // add to registry Zend_Registry::set('config', $this->config); } /** * This method inits the Db connection * * @return boolean */ public function init_db ($server = false) { // Db Objekt erzeugen try { if ($server == false) { $this->db = Zend_Db::factory('Pdo_Mysql', array( 'host' => $this->config->site->local->database->params->host, 'username' => $this->config->site->local->database->params->username, 'password' => $this->config->site->local->database->params->password, 'dbname' => $this->config->site->local->database->params->dbname )); $this->_tablePrefix = $this->config->site->local->database->params->tableprefix; } else { $this->db = Zend_Db::factory('Pdo_Mysql', array( 'host' => $this->config->site->server->database->params->host, 'username' => $this->config->site->server->database->params->username, 'password' => $this->config->site->server->database->params->password, 'dbname' => $this->config->site->server->database->params->dbname )); $this->_tablePrefix = $this->config->site->server->database->params->tableprefix; } $this->db->getConnection(); $this->db->query('SET NAMES utf8'); $this->db->setFetchMode(Zend_Db::FETCH_OBJ); Zend_Db_Table::setDefaultAdapter($this->db); } catch (Zend_Db_Exception $e) { return false; } return true; } public function init_translate () { $this->translate = new Zend_Translate_Adapter_Tmx('../application/languages/langs.tmx', 'de'); //$this->translate->setLocale('de'); //Zend_Validate_Abstract::setDefaultTranslator($this->translate); Zend_Form::setDefaultTranslator($this->translate); } /** * inits the view * modified for smarty * */ public function init_view () { /** * Init the Smarty view wrapper and set smarty suffix to the view scripts. */ $this->view = new Zm_View_Smarty($this->config->site->smarty->toArray()); //use the viewrenderer to keep the code DRY //instantiate and add the helper in one go $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); $viewRenderer->setView($this->view); $viewRenderer->setViewSuffix($this->config->site->smarty->suffix); $viewRenderer->initView(); $viewRenderer->view->doctype('XHTML1_STRICT'); } /** * inits the controllers * */ public function init_front ($server = false) { $this->front = Zend_Controller_Front::getInstance(); $this->front->registerPlugin(new Zm_Controller_Plugin_Layoutloader()); $this->front->addModuleDirectory('../application/modules'); /*$this->front->setControllerDirectory(array( 'default' => '../application/default/controllers', 'admin' => '../application/admin/controllers' ));*/ $this->init_router(); $this->front->registerPlugin(new Zm_Controller_Plugin_Acl(Zend_Auth::getInstance(), new Zm_Acl())); // exception throw no on server if ($server == true) $this->front->throwExceptions(true); else $this->front->throwExceptions(true); // dipatch try { $this->front->dispatch(); } catch(Exception $e) { echo nl2br($e->__toString()); } } /** * inits the specific routes * */ private function init_router() { $router = new Zend_Controller_Router_Rewrite(); $route = new Zend_Controller_Router_Route( 'page/:page', array ( 'module' => 'default', 'controller' => 'page', 'action' => 'show' ) ); $router->addRoute('page', $route); $route1 = new Zend_Controller_Router_Route( 'page/contact', array ( 'module' => 'default', 'controller' => 'page', 'action' => 'contact' ) ); $router->addRoute('page_contact', $route1); $this->front->setRouter($router); /*$router = new Zend_Controller_Router_Rewrite(); $router->addRoute('showpage', new Zend_Controller_Router_Route( 'verein/:pageff', array( 'module' => 'default', 'controller' => 'verein', 'action' => 'index' ) )); $this->front->setRouter($router);*/ } /** * Inits the logger * */ private function init_log ($server = false) { $this->logger = new Zend_Log(); $writer = new Zend_Log_Writer_Firebug(); $this->logger->addWriter($writer); if ($server) { // on server disable logging $writer->setEnabled(false); } } /** * Logs an action * * @param String $msg */ public function log ($msg) { $this->logger->log($msg, Zend_Log::INFO); } /** * Getter for Db, init if not available * * @return Zend_Db */ public function getDb () { if (!isset($this->db) || $this->db->getConnection() == null) $this->init_db(); return $this->db; } public function getConfig () { return $this->config; } public function getOwnerAsArray () { $confA = array(); if (isset($this->config)) $confA = $this->config->toArray(); return $confA['owner']; } public function _getTablePrefix () { return $this->_tablePrefix; } } ?>