From 135fde1f87c7f679fa877a11645b99e001bbe4e1 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sat, 2 Oct 2010 14:11:38 +0200 Subject: [PATCH] Routing update --- application/Bootstrap.php | 142 +++++++----------- application/configs/navigation.xml | 21 +-- library/Fiktiv/Controller/Plugin/Language.php | 18 +-- 3 files changed, 69 insertions(+), 112 deletions(-) diff --git a/application/Bootstrap.php b/application/Bootstrap.php index d69631f..30ec274 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -104,94 +104,62 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $router = $this->getResource('front')->getRouter(); + // Set global lang param + $router->setGlobalParam('lang', 'sv'); + + // Default route to default module + $router->addRoute('default', new Zend_Controller_Router_Route(':lang/:controller/:action/*', + array( + 'module' => 'default', + 'controller' => 'index', + 'action' => 'index' + ))); + + // Allow "direct access" to index controller in default module + $router->addRoute('default-default', new Zend_Controller_Router_Route(':lang/:action/*', + array( + 'module' => 'default', + 'controller' => 'index', + 'action' => 'index' + ), + array( + 'action' => '(about)' + ))); + + + // Routes for blog module + $router->addRoute('blog',new Zend_Controller_Router_Route(':lang/blog/:controller/:action/:id',array( + 'module' => 'blog', + 'controller' => 'index', + 'action' => 'index', + 'id' => '' + ))); + $router->addRoute('blog-default',new Zend_Controller_Router_Route(':lang/blog/:action/:id',array( + 'module' => 'blog', + 'controller' => 'index', + 'action' => 'latest', + 'id' => '' + ),array( + 'action' => '(latest|read|readable)' + ))); + + + // Route for admin? + $router->addRoute('admin', new Zend_Controller_Router_Route(':lang/admin/:controller/:action',array( + 'module' => 'admin', + 'controller' => 'index', + 'action' => 'index' + ))); + + + // Route for auth + $router->addRoute('auth', new Zend_Controller_Router_Route(':lang/:action',array( + 'module' => 'default', + 'controller' => 'auth', + ),array( + 'action' => '(login|logout)' + ))); - /* - * Default routes to the default module - */ - $router->addRoute('default', new Zend_Controller_Router_Route(':lang/:controller/:action', - array( - 'lang' => 'sv', - 'module' => 'default', - 'controller' => 'index', - 'action' => 'index' - ) - )); - - - /* - * This route allows direct access to IndexController - * without specifying "index" as controller. - * - * Allowed actions need to be specified! - */ - $router->addRoute('index', new Zend_Controller_Router_Route( - ':lang/:action', - array( - 'lang' => 'sv', - 'module' => 'default', - 'controller' => 'index', - 'action' => 'index' - ), - array( - 'action' => '(about)' - ) - )); - - - /* - * Route to the blog module - * TODO: This prob. needs changing. - */ - $router->addRoute('blog', new Zend_Controller_Router_Route( - ':lang/blog/:action/:id', - array( - 'lang' => 'sv', - 'module' => 'blog', - 'controller' => 'index', - 'action' => 'latest', - 'id' => '' - ), - array( - 'lang' => '(en|sv)' - ) - )); - - $router->addRoute('portfolio', new Zend_Controller_Router_Route( - ':lang/portfolio/:action', - array( - 'lang' => 'sv', - 'module' => 'default', - 'controller' => 'portfolio', - 'action' => 'index' - ) - )); - - - $router->addRoute('admin', new Zend_Controller_Router_Route( - ':lang/admin/:action', - array( - 'lang' => 'sv', - 'module' => 'blog', - 'controller' => 'index', - 'action' => 'latest' - ) - )); - - - $router->addRoute('auth', new Zend_Controller_Router_Route( - ':lang/:action', - array( - 'lang' => 'sv', - 'module' => 'default', - 'controller' => 'auth', - ), - array( - 'action' => '(login|logout)' - ) - )); - - - return $router; } diff --git a/application/configs/navigation.xml b/application/configs/navigation.xml index 089fa72..6c0c17f 100644 --- a/application/configs/navigation.xml +++ b/application/configs/navigation.xml @@ -3,20 +3,20 @@ - index + default-default default index - blog + blog-default blog index latest - blog + blog-default blog index latest @@ -25,23 +25,21 @@ blog blog - index - archive + archive + index - blog + blog-default blog index readable - - blog + blog-default blog index read - 1 @@ -56,10 +54,13 @@ - index + default-default default index about + + aboutf + \ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php index b401bad..8b7e0ed 100644 --- a/library/Fiktiv/Controller/Plugin/Language.php +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -17,24 +17,12 @@ class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract $config = $bootstrap->getApplication()->getOption('defaults'); $lang = $config['lang']; - $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); - $url = $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('url'); + //$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); + //$url = $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('url'); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); + $redirector->gotoUrlAndExit('/'.$lang); - $pos = strpos($url->url(), $baseUrl); - - if (false === $pos) { - return; - } else { - - - $url = substr_replace($url->url(), $lang, $pos, strlen($baseUrl)); - } - - //echo $url; - $redirector->gotoSimpleAndExit('/sv/blog/archive'); - } if ($translate->isAvailable($lang)) {