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:
- create
subdomain_parameter.php
inside config folder. - inside file have access ther
$container
can manually retrieve current subdomain url , pass container. - import
subdomain_parameter.php
in config.yml
Comments
Post a Comment