duangu1645 2016-01-06 07:17
浏览 252
已采纳

如何用Laravel的url生成器助手生成一个url,参数不在最后?

Normally it is very simple to add parameters using the Laravel url helper method -- as simple as:

url("foo/show/", [333]); // site.com/foo/show/333

However, how do you do it when parameters are at a midpoint, such as:

url("foo/?/bar/?/show", [333,444]); 

I have tried the following which all fail (some come close though):

url("foo/?/bar/?/show", [333,444]); 
// site.com/foo//333/444?/bar/?/show

url("foo/{a}/bar/{b}/show", [333,444]);
// site.com/foo/{a}/bar/{b}/show/333/444

url("foo/{a}/bar/{b}/show", ['a' => 333, 'b' => 444]);
// site.com/foo/{a}/bar/{b}/show/333/444

The ? is obviously important, because it gets close to the result...

Note

I am specifically talking about unnamed routes. So the route function is not in question. Named routes aren't possible in the current project, so I need to reiterate I am looking for the use of the url method.

I 100% agree that normally named routes are the way to go.

  • 写回答

4条回答 默认 最新

  • duanchi0883649 2016-01-06 07:23
    关注

    Try this:

    url(sprintf("foo/%d/bar/%d/show", 333, 444)); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部