1

I created a router and added to the controller like this

public function _initRouting() {          
    // Get Front Controller Instance         
    $front = Zend_Controller_Front::getInstance();  
    // Get Router
    $router = $front -> getRouter();
    $routePage = new Zend_Controller_Router_Route('/page/:action/:cat/:parent/:id', array(
        'controller' => 'page',
        'action'    => 'list',
        'cat'       => 'general',
        'parent'    => '0',
        'module'    => 'default'
    ));
    $router -> addRoute('page', $routePage);
}

First this router is not doing anything, whenever I navigation to /page/list/general/0/1, it takes the standard route, not the new route.

mrN
  • 3,734
  • 15
  • 58
  • 82

1 Answers1

0

The only thing I can think of is the front controller resource has not been "bootstrapped" prior to your init method.

You should at least bootstrap and retrieve the front controller resource

protected function _initRouting()
{
    $this->bootstrap('frontController');
    $front = $this->getResource('frontController');
    // etc

Why don't you just skip creating a bootstrap init method and configure the router resource in your application config?

resources.router.routes.page.route = "page/:action/:cat/:parent/:id"
resources.router.routes.page.defaults.module = "default"
resources.router.routes.page.defaults.controller = "page"
resources.router.routes.page.defaults.action = "list"
resources.router.routes.page.defaults.cat = "general"
resources.router.routes.page.defaults.parent = "0"

As a test, I added the above config and created a PageController with this listAction

public function listAction()
{
    Zend_Debug::dump($this->getRequest()->getParams());
    exit;
}

Calling page/list/general/0/1 yields

array(6) {
  ["action"] => string(4) "list"
  ["cat"] => string(7) "general"
  ["parent"] => string(1) "0"
  ["id"] => string(1) "1"
  ["module"] => string(7) "default"
  ["controller"] => string(4) "page"
}
Phil
  • 157,677
  • 23
  • 242
  • 245
  • @mrN I can't duplicate your problem (see my edited answer). Do you have any other routes defined? – Phil Sep 06 '11 at 12:40
  • Yes, I do have other routes defined as well, but I am giving a seperate name of every route, so I dont think they should class like that. – mrN Sep 08 '11 at 07:15
  • @mrN The order of your routes is most likely is the problem. You need to define them in order of least to most specific. See the *Reverse Matching* note on [this page](http://framework.zend.com/manual/en/zend.controller.router.html) – Phil Sep 08 '11 at 07:54
  • I will check it, but could you help me. on [this question also](http://stackoverflow.com/questions/7344518/dynamic-default-value-selection-in-zend-form-element-multiselect) – mrN Sep 08 '11 at 08:29