dongnuan7956 2011-10-07 14:50
浏览 37
已采纳

在默认的Zend路由中添加可选参数

I want to change the default route on my application to use an optional parameter via Bootstrap.php, not in the application.ini. I am having trouble setting up all "escape" routes, I even don't know If I need to set up several routes or if I can do with only one!

The route must be something like

":module/:area/:controller/:action"

where :area is optional and defaulted to "public"

So in any access to http://www.example.com/my_module/my_controller/my_action I can get via a FC plugin the following:

$request->getParam('area') = "public"

And in http://www.example.com/my_module/my_area/my_controller/my_action I get:

$request->getParam('area') = "my_area"

The main trouble is creating all routes so it escapes to default module, index controller and index action in case those are not passed too and loading http://www.example.com/ returns same as http://www.example.com/default/public/index/index.

And I want to use URL Helper to generate internal URL´s and it respects the correct assembly on this new Default Route.

Edit: I figured that default Route comes with a fail-safe for the module, if it don't exist it defaults to the controller, but how to mimic similar behavior for other parts of the URL and the module itself when creating it in the Bootstrap.

Can anybody give me some light or suggest where can I find an working example ?

  • 写回答

2条回答 默认 最新

  • dongyuqie4322 2011-10-07 22:39
    关注

    The solution was indeed to extend Zend_Controller_Router_Route_Abstract and create a new Route handler to go through the url, verify the existence of modules, areas, controllers and actions to build a full functional url or dispatch to the error controller.

    The heavy work is done between the match() and assemble() methods and I used as reference the Zend class Zend_Controller_Router_Route_Module tht do similar task for the module, but instead of verifying if module exists with the dispatcher I created a whitelist of allowed areas, if it fails to match, it considers that that path part is the controller, the next the action and further parts are parameters.

    It worked like magic!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输