SonataAdminBundle - How to change route to dashboard? - symfony

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

Related

Dynamic routing file SF2

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

How to set default controller and action in symfony2?

How can I set default controller and action in symfony2. Where to configure this settings.
Which annotation do you use?
My default Route is in the file app/config/routing.yml
_index:
pattern: /
defaults: { _controller: ACMEUserBundle:Default:index }
If you have installed with DemoBundle there is a Default Route in the file src/Acme/DemoBundle/Resources/config/routing.yml.
Look the Link it's show some idea to you
http://symfony.com/doc/current/book/routing.html
cant run the controller with symfony 2

symfony/Routing - import yml resource twice

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.

Ordering of routes using annotations

The usual solution when you create routes in symfony and you want to have one route like
/{username}
so that it does not conflict with other routes like /login or /info is just to put that route as your last route in your routing.yml file. Since all the other routes take precedence this conflict is avoided. But how can you do this if you define your routes as annotations in your controllers? Is there any way to specify the ordering of this routes in this case?
In the context of a controller, the order of action methods defines the order of routes. In the context of the whole application, you can import each controller explicitly to control the order, for example:
Home:
resource: "\Vendor\Controller\HomeController"
type: annotation
Security:
resource: "\Vendor\Controller\SecurityController"
type: annotation
security.log_out:
pattern: "/logout"
User:
resource: "\Vendor\Controller\UserController"
type: annotation
I can't comment on the answer, so I will leave how I had to write it in Symfony 2.3 to get it to work:
Home:
resource: "#AcmeBundle/Controller/HomeController.php"
prefix: /home #optional
type: annotation
Notice the change of "\" to "/" and using .php at the end of controller name.
You need to overwrite the rule for that route at the end of your routing.yml. You can do this by using the same name for the route as the one that is automatically created by the annotation. You can find the name with the console command:
php app/console debug:router
So in your routing.yml as the last line you will add:
the_name_of_the_route_as_found_with_appconsole_debug_router:
path:/{username}
defaults: { _controller: YourBundle:YourController:the_action_to_use }
By using the same name it is given by default you will override the original. Don't forget other options that might be important. Like a default value or null for {username} or the method.
You could also remove completely the route from the annotation for the controller. It is not required anymore as it is overwritten anyway :)

Symfony2: Can bundle routes be namespaced?

I have a MagazineBundle which in one of its Twig templates has path('portfolio'), the root of a different bundle that has been prefixed.
# app/config/routing.yml
LameMagazineBundle:
resource: "#LameMagazineBundle/Resources/config/routing.yml"
prefix: /
LamePortfolioBundle:
resource: "#LamePortfolioBundle/Resources/config/routing.yml"
prefix: /portfolio
and
# src/Lame/PortfolioBundle/Resources/config/routing.yml
portfolio:
pattern: /
defaults: { _controller: LamePortfolioBundle:Default:index }
But if I add a third bundle, possibly one I've downloaded and installed, and that bundle also happened to also have a route named 'portfolio', would I have to renamed the routes or is there a way to namespace them?
An experiment I tried with two matching route names results in the last declared one overriding the first.
It's not built into the routing system. You would have to manually prefix your route names with the bundle or some other namespace.
The FOSRestBundle has route prefixing functionality but I'm not sure how coupled it is or if it's something that could be easily used without all the bundles other features.
http://symfony.com/doc/master/bundles/FOSRestBundle/6-automatic-route-generation_multiple-restful-controllers.html#naming-collisions

Resources