简体   繁体   English

Symfony2:动态路由前缀

[英]Symfony2: Dynamic Routing Prefix

I need to create a dynamic routing scheme, where I am prefixing the routes with a variable that changes. 我需要创建一个动态路由方案,在该方案中,我会为路由添加一个更改的变量。

Here's an example: 这是一个例子:

Application Base Route: /dashboard/ 应用基础路线:/ dashboard /

Scenario A: /client_a/dashboard/ 方案A:/ client_a / dashboard /
Scenario B: /client_b/dashboard/ 方案B:/ client_b / dashboard /
Scenario C: /client_c/dashboard/ 方案C:/ client_c / dashboard /

The idea is to keep the application core code all the same, but allow different clients to be referenced in the route. 想法是使应用程序核心代码保持相同,但允许在路由中引用不同的客户端。

What's best practice to set this up? 进行此设置的最佳做法是什么? I can add a static prefix in the routing.yml, but unless the ' prefix: /myparameter ' can be set up dynamically, this may not work for me. 我可以在routing.yml中添加一个静态前缀,但是除非可以动态设置' prefix: /myparameter ',否则这可能对我不起作用。 Primary reason for this is an existing Symfony2 application that is quite complex. 主要原因是现有的Symfony2应用程序非常复杂。

If I am using /{client_name}/dashboard/ , I'll have to change all the paths in the application, since now I have an additional parameter missing in the route. 如果我使用/{client_name}/dashboard/ ,则必须更改应用程序中的所有路径,因为现在路由中缺少一个附加参数。 So, I am looking for a solution that allows me to retrofit the existing application without necessarily having to touch the application main code. 因此,我正在寻找一种解决方案,使我可以对现有应用程序进行改造,而不必触摸应用程序主代码。

Thanks, 谢谢,

JB JB

@Jakub's comment is essentially correct. @Jakub的评论本质上是正确的。 However, if, as in my case, an existing Symfony app has to be retrofitted for this new requirement, it is extremely tedious. 但是,如果像我这样,必须对现有的Symfony应用进行改装以适应此新要求,则这将非常繁琐。 There is furthermore an issue with the security implementation in Symfony in that Symfony requires static paths for the login, login_check, and logout methods. 此外,Symfony中的安全性实现还存在一个问题,即Symfony需要login,login_check和logout方法的静态路径。 So, any use of the prefix in those scenarios doesn't seem to be currently supported. 因此,当前似乎不支持在这些情况下对前缀的任何使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM