Skip to content

Instantly share code, notes, and snippets.

@harikt
Created February 14, 2012 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harikt/1824416 to your computer and use it in GitHub Desktop.
Save harikt/1824416 to your computer and use it in GitHub Desktop.
Routes for ZF , shown in example
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
*
* Routes
*/
protected function _initRoutes()
{
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->removeDefaultRoutes();
$router->setGlobalParam('lang', 'en');
$route = new Zend_Controller_Router_Route(
':lang/:module/:controller/:action/*',
array(
'lang' => 'en',
'module' => 'default',
'controller' => 'index',
'action' => 'index'
)
);
$router->addRoute('default', $route);
$router->addRoute(
'product',
new Zend_Controller_Router_Route(':lang/:country/:province/:city/:product', array(
'lang' => 'en',
'controller' => 'country',
'action' => 'product'
))
);
$router->addRoute(
'city',
new Zend_Controller_Router_Route(':lang/:country/:province/:city', array(
'lang' => 'en',
'controller' => 'country',
'action' => 'city'
))
);
$router->addRoute(
'province',
new Zend_Controller_Router_Route(':lang/:country/:province', array(
'lang' => 'en',
'controller' => 'country',
'action' => 'province'
))
);
$router->addRoute(
'country',
new Zend_Controller_Router_Route(':lang/:country', array(
'lang' => 'en',
'controller' => 'country',
'action' => 'index'
))
);
$router->addRoute(
'contact',
new Zend_Controller_Router_Route(':lang/contact', array(
'lang' => 'en',
'controller' => 'contact',
'action' => 'index'
))
);
}
}
/**
* Current Routes in the above
*
* http://zfroute.local/
* http://zfroute.local/en
* http://zfroute.local/en/contact
* http://zfroute.local/en/country
* http://zfroute.local/en/country/province
* http://zfroute.local/en/country/province/city
* http://zfroute.local/en/country/province/city/product
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment