php - How to pass a variable to routing defaults in Symfony? -


i have symfony2 project multiple brandings (subdomains). each subdomain should use same site functions , same routes (with different hostname). therefor want make subdomain in route path variable. looks like:

mybundle_route:     resource: "@myprojectbundle/controller/"     type:     annotation     prefix:   /     host:     "{subdomain}.%base_host%"     requirements:         subdomain: sub1|sub2 

and routing works. if try generate routes (e.g. in twig), following error because no subdomain variable set:

some mandatory parameters missing ("subdomain") generate url route "company_route".

i don't want add parameter each path() function in project. works perfekt 1 subdomain if add defaults this:

defaults:     subdomain: sub1 

but routes wrong other subdomains. doesn't work

defaults:     subdomain: "%subdomain%" 

all need pass %subdomain% variable defaults or set somewhere in controller constructor. can't find way how going. appreciate help.

if there no better solution try set %subdomain% parameter inside configuration file:

  1. create subdomain_parameter.php inside config folder.
  2. inside file have access ther $container can manually retrieve current subdomain url , pass container.
  3. import subdomain_parameter.php in config.yml

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -