diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 5a1b5bf..fa6f99f 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -23,11 +23,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap return $navigation; } - protected function _initConfig() - { - return new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); - } - /** * View and Layout configuration * @@ -35,13 +30,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap */ protected function _initView() { - $this->bootstrap('config'); - $view = new Zend_View(); $view->setEncoding('UTF-8'); - // Set site title - $view->headTitle($this->getResource('config')->app->name); + // Set site title from application.ini + $config = $this->getApplication()->getOptions(); + $view->headTitle($config['app']['name']); $layout = Zend_Layout::startMvc(); $layout->setLayoutPath(APPLICATION_PATH . '/modules/default/views/layout'); @@ -58,12 +52,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap */ protected function _initFront() { + $this->bootstrap('autoloader'); + // Get front controller $frontController = Zend_Controller_Front::getInstance(); // Set modules directory $frontController->addModuleDirectory(APPLICATION_PATH . '/modules'); + // Add plugins + $frontController->registerPlugin(new Fiktiv_Controller_Plugin_Language()); + return $frontController; } @@ -94,6 +93,55 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap return $router; } + /** + * Configure global and local(modules) models + */ + protected function _initModels() + { + $this->bootstrap('autoloader'); + + // Include global model directory + set_include_path(implode(PATH_SEPARATOR, array( + APPLICATION_PATH . '/models', + get_include_path() + ))); + + // Let our model autoloader plugin handle local models + $front = $this->getResource('front'); + $front->registerPlugin(new Fiktiv_Controller_Plugin_ModelAutoloader()); + + } + + /** + * Configure autoloader + * + * @return Zend_Loader_Autoloader $autoloader + */ + protected function _initAutoloader() + { + $autoloader = Zend_Loader_Autoloader::getInstance(); + $autoloader->registerNamespace('Fiktiv_'); + $autoloader->setFallbackAutoloader(true); + + return $autoloader; + } + + /** + * Configure multilanguage (translator) + * + * @return Zend_Translate $translate + */ + protected function _initTranslate() + { + + $translate = new Zend_Translate('ini', APPLICATION_PATH . '/languages/se.ini', 'sv'); + $translate->addTranslation(APPLICATION_PATH . '/languages/en.ini', 'en'); + + Zend_Form::setDefaultTranslator($translate); + + return $translate; + } + /** * Setup a sweet and simple database * connection. diff --git a/application/languages/en.ini b/application/languages/en.ini new file mode 100644 index 0000000..a4d7696 --- /dev/null +++ b/application/languages/en.ini @@ -0,0 +1,2 @@ +USER_AGE = "Hej %s, du är %s år" +cookie = kaka \ No newline at end of file diff --git a/application/languages/se.ini b/application/languages/se.ini new file mode 100644 index 0000000..a4d7696 --- /dev/null +++ b/application/languages/se.ini @@ -0,0 +1,2 @@ +USER_AGE = "Hej %s, du är %s år" +cookie = kaka \ No newline at end of file diff --git a/application/models/MyModel.php b/application/models/MyModel.php new file mode 100644 index 0000000..a8bf07f --- /dev/null +++ b/application/models/MyModel.php @@ -0,0 +1,6 @@ +name; } } diff --git a/application/modules/default/controllers/IndexController.php b/application/modules/default/controllers/IndexController.php index 5bf3126..546c841 100644 --- a/application/modules/default/controllers/IndexController.php +++ b/application/modules/default/controllers/IndexController.php @@ -5,6 +5,9 @@ class IndexController extends Zend_Controller_Action public function indexAction() { // Here be dragons + $m = new MyModel(); + echo $m->name; + } } \ No newline at end of file diff --git a/application/modules/default/models/MyModel.php b/application/modules/default/models/MyModel.php new file mode 100644 index 0000000..0c9e28a --- /dev/null +++ b/application/modules/default/models/MyModel.php @@ -0,0 +1,6 @@ + - - headTitle()."\n" /* Newline for pretty source :) */ ?> - - - - + + headTitle()."\n" /* Newline for pretty source :) */ ?> + + + + - + - - -
- -
-
- -
- -
- -
-
- - - - - - - - - - - -
abcbab
abcbbb
- - -layout()->content ?> - - + \ No newline at end of file diff --git a/application/modules/default/views/scripts/index/index.phtml b/application/modules/default/views/scripts/index/index.phtml index def4bb6..827a3d8 100644 --- a/application/modules/default/views/scripts/index/index.phtml +++ b/application/modules/default/views/scripts/index/index.phtml @@ -1 +1,29 @@ -Do nothing! \ No newline at end of file +Do nothing! + +translate('cookie'); + +?> + +
+
+ +
+ +
+ +
+
+ + + + + + + + + + + +
abcbab
abcbbb
\ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php new file mode 100644 index 0000000..d2c4b38 --- /dev/null +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -0,0 +1,19 @@ +getParam('bootstrap'); + $translate = $bootstrap->getResource('translate'); + + $lang = $request->getParam('lang'); + + if ($translate->isAvailable($lang)) { + $translate->setLocale($lang); + } + + } +} \ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/ModelAutoloader.php b/library/Fiktiv/Controller/Plugin/ModelAutoloader.php new file mode 100644 index 0000000..ed33c05 --- /dev/null +++ b/library/Fiktiv/Controller/Plugin/ModelAutoloader.php @@ -0,0 +1,20 @@ +getModuleDirectory() . '/models', + get_include_path() + ))); + + } +}