I am using the mod-rewrite router.
我正在使用mod-rewrite路由器。
I am trying to add a Route to the router that will convert the following url:
baseurl/category/aaa/mycontroller/myaction/param/value
我正在尝试将路由添加到将转换以下URL的路由器:baseurl / category / aaa / mycontroller / myaction / param / value
to be:
Controller=mycontroller
action=myaction
to:Controller = mycontroller action = myaction
--parameters--
category=aaa
param=value
I am using the following (not working) in my bootstrap, _front is the frontController
我在我的bootstrap中使用以下(不工作),_front是frontController
$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*');
$Router->addRoute('category', $CategoryRoute);
The error I get is a thrown router exception when I am using the Zend_View::url() helper (with or without giving it the name of the new route).
The exception is thrown only when I have baseurl/category/....
当我使用Zend_View :: url()帮助程序(有或没有给它新的路由的名称)时,我得到的错误是抛出的路由器异常。只有当我有baseurl / category /时抛出异常....
What am I missing?
我错过了什么?
What I missed:
Since there was [category] in the url, The router that was used is the one defined above.
When I used the url() helper, I didn't give any value in it to the [category] hence there was no value for this key in the url parts->failure. Giving a default, makes it work.
我错过了:由于url中有[category],所使用的路由器是上面定义的路由器。当我使用url()帮助器时,我没有给[category]赋值,因此url parts-> failure中没有这个键的值。给出默认值,使其有效。
4 个解决方案
#1
You should include the /* as suggested by solomongaby.
您应该按照solomongaby的建议添加/ *。
If not supplying all of the required parameters (i.e. category, controller and action), you will need to specify defaults.
如果未提供所有必需参数(即类别,控制器和操作),则需要指定默认值。
You can do so as follows:
你可以这样做:
$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*',
array(
'controller' => 'index',
'action' => 'index',
'category' => null
)
);
$Router->addRoute('category', $CategoryRoute);
#2
$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*');
$Router->addRoute('category', $CategoryRoute);
Try adding a start to specify the existence of extra params
尝试添加一个开头来指定额外参数的存在
#3
Please check http://webhkp.wordpress.com/2012/01/01/zend-framework-custom-router/ this would solve your porblem.
请查看http://webhkp.wordpress.com/2012/01/01/zend-framework-custom-router/这将解决您的问题。
its done with an ini file. i like to do it this way
它完成了一个ini文件。我喜欢这样做
#4
You have to specify the defaults when creating the route (see dcaunt's post) OR specify all of the parameters in url view helper (category, controler and action)
您必须在创建路径时指定默认值(请参阅dcaunt的帖子)或在url视图助手中指定所有参数(类别,控制器和操作)
#1
You should include the /* as suggested by solomongaby.
您应该按照solomongaby的建议添加/ *。
If not supplying all of the required parameters (i.e. category, controller and action), you will need to specify defaults.
如果未提供所有必需参数(即类别,控制器和操作),则需要指定默认值。
You can do so as follows:
你可以这样做:
$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*',
array(
'controller' => 'index',
'action' => 'index',
'category' => null
)
);
$Router->addRoute('category', $CategoryRoute);
#2
$Router=$this->_front->getRouter();
$CategoryRoute = new Zend_Controller_Router_Route('category/:category/:controller/:action/*');
$Router->addRoute('category', $CategoryRoute);
Try adding a start to specify the existence of extra params
尝试添加一个开头来指定额外参数的存在
#3
Please check http://webhkp.wordpress.com/2012/01/01/zend-framework-custom-router/ this would solve your porblem.
请查看http://webhkp.wordpress.com/2012/01/01/zend-framework-custom-router/这将解决您的问题。
its done with an ini file. i like to do it this way
它完成了一个ini文件。我喜欢这样做
#4
You have to specify the defaults when creating the route (see dcaunt's post) OR specify all of the parameters in url view helper (category, controler and action)
您必须在创建路径时指定默认值(请参阅dcaunt的帖子)或在url视图助手中指定所有参数(类别,控制器和操作)