Pergunta

I don´t know what I do wrong. I got two named Zend route:

$route = new Zend_Controller_Router_Route(
                    'catalog/:categoryIdent/:productIdent/',
                    array(
                        'action' => 'viewproduct',
                        'controller' => 'catalog',
                        'module' => 'eshop',
                        'categoryIdent' => '',
                        'productIdent' => ''                        

                    ),
                    array(
                        'categoryIdent' => '[a-zA-Z-_0-9]+',
                        'productIdent' => '[a-zA-Z-_0-9]+'
                    )
    );
    $router->addRoute('catalog_category_product', $route);

    // catalog category route
    $route = new Zend_Controller_Router_Route(
                    'catalog/:categoryIdent/:page/',
                    array(
                        'action' => 'viewcategory',
                        'controller' => 'category',
                        'module' => 'eshop',
                        'categoryIdent' => '',
                        'page' => ''

                    ),
                    array(
                        'categoryIdent' => '[a-zA-Z-_0-9]+'
                    )
    );

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

When I call catalog_category its all fine but when I try call to catalog_category_product is used viewcategory action from second route. It means its problem with :page variable in url, resp. same count of arguments in URL? I think that itsn´t nessesary I would like to get two different but similar routes - for example:

For category - catalog/category1/1

For product - catalog/category1/product1 (without number of page)

when I change form of route catalog_category_product to catalog/:categoryIdent/something/:productIdent/ so its working

here is route calls

$this->url(array('categoryIdent' => categoryIdent, 'productIdent' => productIdent), 'catalog_category_product', true);

$this->url(array('categoryIdent' => 'cerveny-cedr', 'page' => 'pageNumber'), 'catalog_category', true);

Thanks for any help

Foi útil?

Solução

Keep in mind that routes are checked in reverse order, so the ZF router will check the catalog_category route before the catalog_category_product route when matching URLs. So, the number of arguments is not a problem, but since you've not put any sort of restriction on the 'page' parameter, all URLs that would normally match your catalog_category_product URL will be matched by catalog_category instead.

It sounds like 'page' should be numeric, so adding that restriction to your second route should fix the problem.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top