I am currently stuck on the multi-site management in Symfony2.
I have a Symfony2 project that allows multiple sites. Everything works fine but I block on managing files "routing".
My /app/config/routing.yml file I wish I could load the correct file routing.yml compared to the domain name:
project_routing:
resource: "%MY_DOMAIN%/routing.yml"
Unfortunately I can not put variable %my_domain% a file routing so I do not see how to fix this ...
The structure:
app/config/routing.yml is redirected to my %my_domain%
app/config/www.mywebsite.com/routing.yml
app/config/www.otherwebsite.com/routing.yml
So 1) base locale you can specify in app/parameters.yml
like this:
parameters:
locale: en
where locale: en default locale.
2) In default app/routing.yml file you should specify link for routing in your bundle like this:
fob_rental:
resource: "#fobRentalBundle/Resources/config/routing.yml"
prefix: /
3) In my src/fob/RentalBundle/Resources/config/routing.yml route looks like:
fob_offer_new:
pattern: /{_locale}/offers/new
defaults: { _controller: fobRentalBundle:Offer:new }
requirements:
_locale: en|spa
Related
I'd like to prefix all my urls by an optional _locale. BTW, I'm handling fr and en.
The point is, when _locale is given I'll use it thanks to symfony Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest, if not I'll use the locale saved in the database thanks to my own listener (priority: 15) which runs immediately after the previous one.
What I've tried so far is the following:
app/config/routing.yml
entrypoint:
resource: 'locale_prefixed_routing.yml'
prefix: /{_locale}
And locale_prefixed_routing.yml imports bundles routings.
/fr/url/example works but /url/example does not and returns 404 page.
How do I tell symfony to use the locale in the url, if does not exist use the one in the database?
I suppose your routes are defined like this in your locale_prefixed_routing.yml :
my_route:
path: /
defaults:
Actually routes like /url/example without any locale are not defined in your routing because you ask to prefix all the routes loaded in locale_prefixed_routing.yml by the locale. So it is normal to get an error when requesting such a route without locale.
You can try to make another routing file named non_localized_routing.yml containing the same routes except that you will use specific defaults.
Example :
route_example:
path: /url/example
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /{_locale}/url/example
permanent: true
Tell me if it permits you to get rid of your problem, I haven't test it yet.
For me it sounds weird to store the locale in the database when the locale is not provided by the user. You can simply add a default one:
framework:
default_locale: en
Say my application currently responds to the /products route just fine. How do I setup Ember.JS so that /app_dev.php/products would be the same route?
If I understand your problem right, you need to generate Symf route via js instead of static "/products" route?
If so you should use FOSJsRoutingBundle https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
Just set option "expose" to your routing as:
app/config/routing.yml
my_products:
pattern: /products
defaults: { _controller: ProductBundle:Products:index }
options:
expose: true
then you can generate the route depends on env from javascript as:
Routing.generate('my_products')
I'm trying to enable optional locale placeholder for all the routes without duplicating everything. My routes look like this:
site:
prefix: /
resource: "routes-site.yml"
site_i18n:
prefix: /{_locale}
resource: "routes-site.yml"
defaults: {_locale: pl}
requirements:
_locale: 'en'
But I get only site_i18n working. Why I cannot import same resource multiple times?
It's Symfony 2.2
Because the routes have same route name, the later import overrides routes from the first one.
Have a look at: BeSimpleI18nRoutingBundle. It allows you even localize the whole path, but in this case, you will just need localize prefix.
I have installed Symfony 2.2.0 with SonataAdminBundle. Now I'd like to change default dashboard route from /dashboard to /.
How to do it in a right way?
You can use as below into your app/config/routing.yml file:
default:
pattern: /admin/
defaults: { _controller: SonataAdminBundle:Core:dashboard }
You can try this
Create a copy of the sonata route file
https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/config/routing/sonata_admin.xml
and make necessary changes. Save the file in one of your bundles
In your app/config/routing.yml refer to this route file
admin:
resource: '#AcmeAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
I try to load a localized_routes.yml inside the main routing.yml file with :
localized_routes:
resource: "routing_localized.yml"
prefix: /{_locale}
requirements: { _locale : fr|es|it|de }
But it doesnt work at all, the requirements are not in the generated URL checks and so I can use any locale I want .... I see in the Symfony source that only the prefix are taken, not requirements or defaults values, is it an issue ?