2009-10-09 21:55
浏览 34

如何将Zend Framework的路由模式更改为不使用键/值对?

Rather than using controller/action/key1/value1/key2/value2 as my URL, I'd like to use controller/action/value1/value2. I think I could do this by defining a custom route in my Bootstrap class, but I want my entire application to behave this way, so adding a custom route for each action is out of the question.

Is this possible? If so, how would I then access valueN? I'd like to be able to define the parameters in my action method's signature. e.x.:

 // PostsController.php

 public function view($postID) {
      echo 'post ID: ' . $postID;

I'm using Zend Framework 1.9.3


图片转代码服务由CSDN问答提供 功能建议

而不是使用 controller / action / key1 / value1 / key2 / value2 作为我的URL ,我想使用 controller / action / value1 / value2 。 我想我可以通过在我的Bootstrap类中定义自定义路由来实现这一点,但我希望我的整个应用程序都以这种方式运行,因此为每个操作添加自定义路由是不可能的。

这可能吗? 如果是这样,我将如何访问 valueN ? 我希望能够在我的action方法的签名中定义参数。 e.x。:

  // PostsController.php 
公共函数视图($ postID){
 echo'post ID:'。  $ postID; 

我正在使用Zend Framework 1.9.3

谢谢! \ n

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongpan2788 2009-10-10 09:06

    While I don't think it's possible with the current router to allow N values (a fixed number would work) you could write a custom router that would do it for you.

    I would question this approach, however, and suggest that actually listing all of your routes won't take long and will be easier in the long run. A route designed as you've suggested would mean that either your named parameters are always in the same order, i.e.


    or that they are almost anonymous


    With code like

    $this->getRequest()->getParam('value2'); //fairly meaningless
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题