Symfony2: Add a prefix route to a bundle - symfony

I am working with Symfony2 and I have a bundle that includes multiple controllers. I want to have a common prefix route for all of them.
Something like this:
bundle_path/controller1_path
bundle_path/controller2_path
bundle_path/controller3_path
etc.
Is there a way to do this without writing bundle_path into every single controller?

You can add a prefix to alle the bundle's route in the routing.yml files. As Example:
acme_customer_area_frontend:
resource: "#AcmeCustomerAreaFrontendBundle/Resources/config/routing.yml"
prefix: /customer/frontend
Hope this help

Related

Symfony: Enable routes only in custom condition

I have my routing.yml file and inside it i define the the routing files of all the application's bundles.
test_route:
resource: "#test/routing.yml"
prefix: /
test_route_2:
resource: "#test_2/routing.yml"
prefix: /
What i want to achieve is to enable the previous routes only under a custom condition. I want to pass a function there so i can make some complicated checks.
I don't know is Symfony supports this, so any kind of help/idea is welcome.

Different path to same routing file from main routing file in Symfony2

I have 7 bundles in my project. So I pointed each from main routing file (app->config->routing.yml).
I have a requirement that same routing file inside a bundle can able to be called using different paths. Like one path with an argument and other without argument.
My main routing file looks like as follows
clubadmin_general:
resource: "#TestGeneralBundle/Resources/config/routing.yml"
host: "mywebsite"
prefix: /{url_identifier}/admin/
clubadmin_general_club_domain:
resource: "#TestGeneralBundle/Resources/config/routing.yml"
prefix: /admin/
The routing file inside the bundle is common when called form main routing file. The routing file inside the bundle is looks like..
show_dashboard:
pattern: /
defaults: { _controller: TestGeneralBundle:Dashboard:index }
When I called, routing defined first gives "No route found". But the second works well. When I changed the order, always second works well.
In the above code path "/admin/" works well. But path "/{url_identifier}/admin/" will not work.
I think "show_dashboard" name is cached for a route. May be that is the issue. But couldn't find a solution.
Someone please help me.
Finally found a solution... By create different environment, the cache folder get separated and then can able to use same routing names with different paths.

Change default path on Symfony CMF

I installed Symfony CMF structure bundles on my project, but default route is on
localhost/project/web/app_dev.php/
and i want to show it on
localhost/project/web/app_dev.php/cms
Thank you!!
So you do want to install symfony at the webroot, right? If that is the case, your best bet is to add a route /cms and add everything else under that route, instead of directly to the root. When using the RoutingAutoBundle, this should be no problem to configure. If your editors create routes themselves, you would need to work with the widget for selecting the parent of the routes to only propose the cms/ route you created - unless you think it could make sense for them to occasionally place a route outside of /cms.
If you want to be more strict, i think your best bet is the upcoming ResourceBundle. Discuss this with Dan over at https://groups.google.com/forum/#!topic/symfony-cmf-devs/6Wha2o3qHPE
Not sure if I understood your question. If you want your default home page at localhost/project/web/app_dev.php/ pointing to your cmf bundle, just add this at the begining of app/config/routing.yml
homepage:
pattern: /
defaults: { _controller: YourCMFBundle:Welcome:index }
Where Welcome is the name of your CMF default controller.

Symfony2: add routes from my bundle

I created a bundle wjb/ImageBundle but I would like to load its routes without modifying app/config/routing.yml. From FOSRestBundle and few more, I see it is possible but I coudn't figure a way how to do that.
Is there some idiot-proof tutorial? I would like to use annotations but I would accept any other way too.
It's not possible to have routes in your application without registering them.
FOSUserBundle's routes can partly be defined in your security.firewalls configuration.
The others have to be imported as well described in the documentation chapter #6 - FOSUserbundle import routing files.
A workaround may be adding routes when loading a bundle without touching your routing.yml in a CompilerPass.

Controller subdirectories?

I would like to isolate some controllers in a subdirectory in my Symfony2 app.
Something like that:
route:
resource: "#MyBundle/Controller/Admin/"
type: annotation
prefix: /admin/
In this directory there is 6 controller class.
I can import these separatly but it's not practical ...
Thanks for your help.
I use this which includes every controller in that folder:
core:
resource: "#AppCoreBundle/Controller"
type: annotation
The same code applies to subfolders:
core_admin:
resource: "#AppCoreBundle/Controller/Admin"
type: annotation
It's perfectly okay to create subfolders inside the Controller folder to split your public and admin controllers.
Of course you could include each of them one by one instead, but that's extremely tedious.
You don't need to do anything special, the code below includes subdirectories like
/Controller/admin/
for example.
app:
resource: "#AppBundle/Controller/"
type: annotation
Its not good practice to do like that.
Why can you make the extra bundle if you really like to isolate the stuff.
Then you can make them as service and access from where ever you want
See here http://symfony.com/doc/2.0/cookbook/controller/service.html

Resources