dsvcqvp139098 2014-12-10 17:54
浏览 185

Phalcon URL生成器混合自定义路由中的参数

I'm trying to get the following route to work:

$router->add('/([a-z]{2})/:namespace/:controller/:action/([^\/]+)', array(
    'language' => 1,
    'namespace' => 2,
    'controller' => 3,
    'action' => 4,
    'location' => 5

The relevant (and for testing purposes only) line in the Volt template looks like this:

{{  url({'for': 'location', 'namespace': 'weather', 'controller': 'forecast', 'action': 'precipitation', 'location': 'Hamburg' }) }}

What I want is //weather/forecast/precipitation/Hamburg but instead all I get is //weather/forecast/precipitation/.

Next thing I tried was

$router->add('/([a-z]{2})/:namespace/:controller/:action/{location:[^\/]+}', array(
    'language' => 1,
    'namespace' => 2,
    'controller' => 3,
    'action' => 4,

which at least gives me the location in the URL, but at a totally wrong position: //Hamburg/forecast/precipitation/.

Now I've looked into the Library\Mvc\Router and the array that is passed to get() looks fine to me:

    [for] => location
    [namespace] => weather
    [controller] => forecast
    [action] => precipitation
    [location] => Hamburg
    [language] => en

I will use my own Router to handle translated URLs, so I think we can ignore the language parameter for now. So far, the custom Router does nothing more than call the original one.

Any idea how to get the location parameter to work?

  • 写回答

1条回答 默认 最新

  • duanmeng3573 2014-12-11 13:15

    I've tested all possibilities given in the router documentation and even take a look in the router implementation for Phalcon 2.0 (are you using this version, right?!). The only thing that worked out was to not use named parameters at all, even the built-in placeholders needed to be removed from the route pattern:

    $this->add('/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_]+)/([^\/]+)', array(
        'namespace' => 1,
        'controller' => 2,
        'action' => 3,
        'location' => 4,

    In other words, this seems like a bug to me. Feel free to file a bug to investigate further.

    About the language parameter, I don't know if you already saw this question, but you can deal with this in a similar way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 布尔运算推导,请证明
  • ¥15 有没有人会打学生成绩管理系统呀
  • ¥15 在使用Fiddler和夜神模拟器抓包的时候一直出现443该怎么办啊QAQ搜了好几个笔记都没有解决
  • ¥15 3x7的二维数组A、B、C,A中的任意1个数组元素与B的任意1个数组元素、同时又与C的任意1个数组元素比较,把不同位置出现相同数的比较称为无意义,反之称为有意义,把有意义的比较打印输出。
  • ¥20 预测模型怎么处理原始数据(随机森林)
  • ¥20 请问discuz3.5如何实现插入ckplayer全能播放器功能呢?
  • ¥15 thingsboard代码编译出错误
  • ¥15 博途v18仿真报错怎么解决
  • ¥15 欧姆龙plc枕式包装机 ST编程
  • ¥15 为啥快手广告联盟的广告这么难出来