Symfony 2.0-如何使用数组参数创建路由? [英] Symfony 2.0 - How to create route with array-parameters?
问题描述
我想创建一个在数组上匹配的路由。
I want to create a route, that matches on an array.
示例:
Name_show:
pattern: /Name/{names}
defaults: { _controller: testBundle:Name:showNames }
其中 {names}
保存一个名称数组,例如:
where {names}
holds an array of names, like:
array( [1] =>'托马斯',[2] =>'安东',[3] =>'贝塔');
如何处理?使用
的Symfony 2.0响应警告:preg_match()期望参数2为字符串,给定数组
在symfony文档中找不到任何解决方案。
can't find any solution in symfony doc.
推荐答案
您可以使用它作为字符串,只是 serialize()
之前和之后的内容。
You can use it as a string and just serialize()
the content before and after.
据我所知symfony2不如果不允许在路由中使用数组,那么带有数组的URL将如何显示? URL必须是字符串,因此序列化数组并将其作为字符串传递可能是更好的选择。
As far as I know symfony2 doesn't allow arrays in routing, how would the URL Look with an array in? A URL has to be a string, so serializing the array and passing it as a string is probably a better option.
这篇关于Symfony 2.0-如何使用数组参数创建路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!