From 34491e8a6f5183f2504d0cc3eac47433643fd880 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sun, 29 Aug 2010 12:42:25 +0200 Subject: [PATCH] Model / db structure test + some random fix --- TODO | 3 + application/Bootstrap.php | 19 ++++- application/configs/application.ini | 4 ++ application/languages/se.ini | 3 +- application/models/User.php | 19 +++++ application/models/Users.php | 22 +++++- .../blog/controllers/IndexController.php | 1 - .../default/controllers/IndexController.php | 13 +++- .../default/views/scripts/index/index.phtml | 19 +++++ .../Controller/Action/Helper/DbService.php | 17 +++++ library/Fiktiv/Controller/Plugin/Language.php | 10 ++- library/Fiktiv/Db/Service.php | 72 +++++++++++++++++++ 12 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 TODO create mode 100644 application/models/User.php create mode 100644 library/Fiktiv/Controller/Action/Helper/DbService.php create mode 100644 library/Fiktiv/Db/Service.php diff --git a/TODO b/TODO new file mode 100644 index 0000000..b4b206d --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +- Add mongoDB support +- Implement gravatar support +- \ No newline at end of file diff --git a/application/Bootstrap.php b/application/Bootstrap.php index c3e1223..3bfd51a 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -4,6 +4,13 @@ */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { + protected function _initDev() + { + // TODO: Move this out of dev. + Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/../library/Fiktiv/Controller/Action/Helper', 'Fiktiv_Controller_Action_Helper'); + } + + /** * Setup navigaion * @@ -98,7 +105,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $this->bootstrap('front'); $router = $this->getResource('front')->getRouter(); - + $route = new Zend_Controller_Router_Route( ':lang/:module/:controller/:action/*', array( @@ -106,7 +113,10 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'module' => 'default', 'controller' => 'index', 'action' => 'index' - ) + ), + array( + 'lang' => '[a-z]{2}' + ) ); $router->addRoute('default', $route); @@ -188,6 +198,11 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap // Use the adapter by default Zend_Db_Table::setDefaultAdapter($database); + // Fire up the db service for easier access to the tables + // TODO: Better definition of tables in the database, maybe read meta? + $dbLayer = Fiktiv_Db_Service::getInstance(); + $dbLayer->setTables(array('users')); + return $database; } diff --git a/application/configs/application.ini b/application/configs/application.ini index 63d226d..6e6c177 100644 --- a/application/configs/application.ini +++ b/application/configs/application.ini @@ -8,7 +8,11 @@ app.name = "Fiktivkod" app.version = "1.0" app.url = "fiktivkod.org" +// Defaults +defaults.lang = sv + // Database +db.adapter = mongo db.host = 127.0.0.1 db.username = fiktivkod db.password = pw diff --git a/application/languages/se.ini b/application/languages/se.ini index 9c85ff9..5ef003f 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -16,8 +16,9 @@ ERROR_404 = "Sidan kunde inte visas" ERROR_404_TXT = "Sidan du försöker besöka existerar inte." ERROR_500 = "Oops, något blev fel" ERROR_500_TXT = "Vi kollar på detta så fort vi kan." + ERROR_TXT_WHAT = "Följande har gått fel" class = klass function = funktion -line = rad \ No newline at end of file +line = rad diff --git a/application/models/User.php b/application/models/User.php new file mode 100644 index 0000000..27bdc81 --- /dev/null +++ b/application/models/User.php @@ -0,0 +1,19 @@ +toArray(), array_flip($this->_hiddenFields))) . '}'; + } +} \ No newline at end of file diff --git a/application/models/Users.php b/application/models/Users.php index faeb8d5..39c09eb 100644 --- a/application/models/Users.php +++ b/application/models/Users.php @@ -1,12 +1,14 @@ fetchRow($this->getAdapter()->quoteInto('email = ?', $email)); + } + + return null; + } } \ No newline at end of file diff --git a/application/modules/blog/controllers/IndexController.php b/application/modules/blog/controllers/IndexController.php index f2d5ff2..ec805dd 100644 --- a/application/modules/blog/controllers/IndexController.php +++ b/application/modules/blog/controllers/IndexController.php @@ -4,6 +4,5 @@ class Blog_IndexController extends Zend_Controller_Action { public function indexAction() { - } } diff --git a/application/modules/default/controllers/IndexController.php b/application/modules/default/controllers/IndexController.php index 3bdb90e..e746cf6 100644 --- a/application/modules/default/controllers/IndexController.php +++ b/application/modules/default/controllers/IndexController.php @@ -12,6 +12,17 @@ class IndexController extends Zend_Controller_Action public function aboutAction() { - + //$dbLayer = Fiktiv_Db_Service::getInstance(); + //$me = $dbLayer->users->findByEmail('fredric@fiktivkod.org'); + + $dbLayer = $this->_helper->dbService(); + $me = $dbLayer->users->findByEmail('fredric@fiktivkod.org'); + /* + $users = new Users(); + $me = $users->findByEmail('fredric@fiktivkod.org'); + $dbLayer->users->findByEmail(); + */ + echo $me; + } } \ 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 4c7f57c..2d1412c 100644 --- a/application/modules/default/views/scripts/index/index.phtml +++ b/application/modules/default/views/scripts/index/index.phtml @@ -3,6 +3,25 @@

translate('START_TXT') ?>

+ $val ) + $url .= ' ' . $key . '="' . $val . '"'; + $url .= ' />'; + } + return $url; +} + +echo '' + +?> +

Translated: translate('uw:example', 'home', 'about', true) ?>

diff --git a/library/Fiktiv/Controller/Action/Helper/DbService.php b/library/Fiktiv/Controller/Action/Helper/DbService.php new file mode 100644 index 0000000..80d9853 --- /dev/null +++ b/library/Fiktiv/Controller/Action/Helper/DbService.php @@ -0,0 +1,17 @@ +dbService(); + } +} \ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php index 31211a7..558ba11 100644 --- a/library/Fiktiv/Controller/Plugin/Language.php +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -4,17 +4,21 @@ */ class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract { - public function preDispatch(Zend_Controller_Request_Abstract $request) + public function routeShutdown(Zend_Controller_Request_Abstract $request) { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $translate = $bootstrap->getResource('translate'); $lang = $request->getParam('lang'); + // If lang is not supplied we use default. + if (is_null($lang)) { + $config = $bootstrap->getApplication()->getOption('defaults'); + $lang = $config['lang']; + } + if ($translate->isAvailable($lang)) { $translate->setLocale($lang); } - - } } \ No newline at end of file diff --git a/library/Fiktiv/Db/Service.php b/library/Fiktiv/Db/Service.php new file mode 100644 index 0000000..264454f --- /dev/null +++ b/library/Fiktiv/Db/Service.php @@ -0,0 +1,72 @@ +_tables[$tbl] = null; + } + } + + /** + * Provides access to the underlaying table objects. + * + * @param $name + * @return Zend_Db_Table_Abstract + */ + public function __get($name) { + + if (array_key_exists($name, $this->_tables)) { + + if (!($this->_tables[$name] instanceof Zend_Db_Table_Abstract)) { + + $class = ucfirst($name); + $this->_tables[$name] = new $class(); + } + } + + return $this->_tables[$name]; + } + +} \ No newline at end of file