donglou8371 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

Thanks!

  • 写回答

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.

    /controller/action/id/title/colour
    

    or that they are almost anonymous

    /controller/action/value1/value2/value3
    

    With code like

    $this->getRequest()->getParam('value2'); //fairly meaningless
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮