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:

<?php

$router = new Zend_Controller_Router_Rewrite();
$route = new Zend_Controller_Router_Route(
'product/:name',
array(
'controller' => 'products',
'action' => 'display'
)
);

$router->addRoute('product',$route);
?>

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/

zfproject
  - application
    - configs
      application.ini
    + controllers
    + layouts
    + modules
    + views
      bootstrap.php
  + docs
  - library
    + Zend
  - public
      .htaccess
      index.php
  + tests

Thanks

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)


//BootStrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

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

        $router->addRouter(
                'itemParam',
                new Zend_Controller_Router_Route(
                        '/display/:item',
                        array('controller' => 'products', 'action' => 'display')
                )
        );
}

}


And this is my Controller:


//ProductsController.php

class ProductsController extends Zend_Controller_Action
{

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

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

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


And finally my view:



//display.phtml

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


I wonder what I’m now getting wrong