rename a zend module with routes

2019-08-27 12:22发布

I have a route to rename the 'items' module to 'products', and it works in most cases, but not when there is no controller or action explicitly set in the url. For example, example.com/products does not work, while example.com/items does, and is the same as example.com/products/index/index. Any ideas how to fix it, or to make controllers and actions optional?

$router->addRoute('item-alias', new Zend_Controller_Router_Route('products/:controller/:action', array(
    'module'=>'items'
)));

Edit:

It seems to work when I changed it to

$router->addRoute('item-alias', new Zend_Controller_Router_Route('products/:controller/:action/*', array(
    'module'=>'items'
    'controller'=>'index',
    'action'=>'index'
)));

The '*' allows additional optional parameters to be appended, e.g. example.com/products/index/index/page/2

1条回答
可以哭但决不认输i
2楼-- · 2019-08-27 13:22

set default values for controller and action. That way they will be optional parameters and can be skipped.

查看更多
登录 后发表回答