Zend Custom Routing

Trying to understand Custom routes. I basically have no problem making route settings in application.ini but I want to do it another way. I checked the documentation but it aint clear as to where im supposed to place this code, for example:


$router = new Zend_Controller_Router_Rewrite();
$route = new Zend_Controller_Router_Route(
'controller' => 'products',
'action' => 'display'


So do I place it in boostrap.php, index.php or the controller in this case “products”? Else I’m I missing something?

project/directory structure: /Applications/MAMP/htdocs/zfproject/

  - application
    - configs
    + controllers
    + layouts
    + modules
    + views
  + docs
  - library
    + Zend
  - public
  + tests


Routes should go in your bootstrap file. They affect the entire application and are processed before the code even gets to the controller, so putting them in the controller would not work. Technically, you could also put routing info in index.php, I worked fo a company that did that, but it’s messy and less organized than putting it in the bootstrap file.

Now I have them set in my bootstrap.php and Im trying to access the variable but i am not getting anything: (Using version 1.11)


class Bootstrap extends Zend_Application_Bootstrap_Bootstrap

public function initWithRoutes(){
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();

                new Zend_Controller_Router_Route(
                        array('controller' => 'products', 'action' => 'display')


And this is my Controller:


class ProductsController extends Zend_Controller_Action

    public function init()
        /* Initialize action controller here */

    public function indexAction()
        // action body
    public function displayAction(){
            $this->view->product = $this->_request()->getParam('item');

        } else {
            $this->view->product = 'nothing was passed';

And finally my view:


<?php echo $this->product; ?>

I wonder what I’m now getting wrong