문제

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