symfon 1.4根据插件内的url参数加载不同的routing.yml
我有一个插件,我需要根据查询字符串中的变量加载不同的routing.yml 文件。
示例:
if($request->getParameter('page'){
// use routingPage.yml
}
else{
// use another routing.yml
}
因此,如果 url 中的 page 参数为 url_for('@route1'),将返回一个 url,否则相同的 url_for('@route1') 将返回其他 url。
如何重写 rouing.yml 加载机制来执行我想要的操作?
I have a plugin and i need to load a different routing.yml file based on a variable in the query string.
Example:
if($request->getParameter('page'){
// use routingPage.yml
}
else{
// use another routing.yml
}
So, If the page parameter in url the url_for('@route1'), will return one url, else the same url_for('@route1') would return other url.
How can override the rouing.yml loading mechanism to do what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个应用程序只能有一个
routing.yml
(当然它可以被其他插件覆盖)。原因很简单:如果您想使用多个路由文件(例如
routing1.yml
和routing2.yml
),并且它们都有一个名为route1
,分别重定向到controller1/action
和controller2/action
。也许您可以在视图中切换它,并在一种情况下转到
controller1/action
,在另一种情况下转到controller2/action
。但是,当新请求到达时,前端控制器正在确定要执行哪个控制器/操作:现在如何使用哪个routing.yml
?所以我不知道你到底想要实现什么,但我会在你的
routing.yml
中选择两条路线,并根据你的视图参数选择路线。Every application can have only one
routing.yml
(of course it can be overrided by other plugins).The reason for this is quite simple: If you want to use multiple routing files (say
routing1.yml
androuting2.yml
), and they both have a route calledroute1
, which redirects tocontroller1/action
andcontroller2/action
respectively.Maybe you would be able to switch it in the view, and go to
controller1/action
in the one case andcontroller2/action
in the other. But then: when a new request arrives, and the front controller is determining which controller / action to execute: how does it now whichrouting.yml
to use?So I don't know exactly what you're trying to achieve, but I would go for two routes in your
routing.yml
, and select the route based on your view parameters.