Frederick Marcoux
Frederick Marcoux

Reputation: 2223

Zend Router - URL with or without parameters are two differents routes

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).

Upvotes: 2

Views: 294

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

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.

Upvotes: 1

Related Questions