I'm currently creating a new version of my website using Zend Framework and I'm stuck with a little problem I've seen in the past.

There are my routes: (a part)

// BLOG -> CATEGORIES
$route = new Zend_Controller_Router_Route(
    'blog/categories',
    array(
        'module'     => 'blog',
        'controller' => 'categories',
        'action'     => 'index'
    )
);
$router->addRoute('blog-categories', $route);

// BLOG -> CATEGORIES -> LIST ARTICLES (:alias = name of the category)
$route = new Zend_Controller_Router_Route(
    'blog/categories/:alias',
    array(
        'module'     => 'blog',
        'controller' => 'categories',
        'action'     => 'list',
        'alias'      => null
    )
);
$router->addRoute('blog-categories-list', $route);

The problem is that: when I go to /blog/categories/, it brings me the list action. What I don't want. I need the index.

Is there a way to fix that without using, for exemple, /blog/categories/view/:alias ?

Note: I have the same problem for /blog/ (list all articles) and /blog/:alias/ (display single article).

有帮助吗?

解决方案

By including 'alias' => null you're specifying a default value for the :alias parameter, used if it is not in the URL. This is why your second route is always matching. Remove this and it should work as you are wanting it to.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top