0
votes

I have one module (site) in my zend framework app. What I am trying to do is first to check if controller/action exists and if not then try to match the URL against some custom routes.

My code in _bootstrap.php is as follows:

$router = $this->frontController->getRouter();
$router->removeDefaultRoutes();

// catalog category product route
$route = new Zend_Controller_Router_Route(
        ':categoryIdent/:productIdent',
        array(
            'action'        => 'view',
            'controller'    => 'product',
            'module'        => 'site',
            'categoryIdent' => '',
            'productIdent' => ''
        ),
        array(
            'categoryIdent' => '[a-zA-Z-_0-9]+',
            'productIdent'  => '[a-zA-Z-_0-9]+'
        )
);

$router->addRoute('catalog_category_product', $route);


$router->addDefaultRoutes();

I know that the routes in Zend Framework are matched backwards. So I tried the following URLs.

  1. example.com/site/index/index -> OK (executing action/controller => index/index)
  2. example.com/bags/bag-7 -> OK (executing action/controller => product/view)
  3. example.com/index/index -> WRONG ( executing action/controller => product/view, but this should be a part from the default routes, which are defined at the end)

This is the problem and I don't understand why the default controller/action route is not applied.

1

1 Answers

0
votes

Your third example matches the pattern of your catalog_category_product-route. That is why it is send to product/view.

You could try to add requirements to :productIdent and/or :categoryIdent, so that index/index does not match these requirements.

The reference manual explains how to set variable requirements.

edit: I missed, that you already placed requirements. But index/index still does match :categoryIndent/:productIndent. You could use the following regex for :productIndent, assuming that it is always word - dash - number:

'/^([a-z]+-[0-9]+)$/'