Symfony: Enable routes only in custom condition - symfony

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.

Related

How to secure Lexik Translation Bundle routes?

I am using Symfony 2.8 and I import my translations into the database with the help of the Lexik translation bundle - this allows me to have a route like /admin/translations where i can see statistics and add more translations (well, the customer will).
The problem is that this route has no security at all. I can just access it without even being logged in. I have an annotation that makes sure you have a certain role in order to access the given route.
My question is how can I add my custom annotation to the lexik controller that renders the translation templates (like overview and grid pages) without actually writing code inside the bundle (vendor folder). Is there a way to add it in the config?
In your security.yml you just need to add access control on the admin path
access_control:
- { path: ^/admin, role: ROLE_ADMIN }

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.

Symfony2: Add a prefix route to a bundle

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

What are the different frontends that can be set with OneupUploaderBundle?

What are the different frontends that can be set with OneupUploaderBundle in the config.yml file?
I googled this and I found some frontend like: mooupload, blueimp.
What is the full list?
# app/config/config.yml
oneup_uploader:
mappings:
gallery:
frontend: blueimp # or any uploader you use in the frontend
Is it possible to use VichUploaderBunde as frontend in OneupUploaderBundle?
If you are curious about what type of configuration it supports and have no time to look in the documentation, then you can open the OneupUploaderBundle Configuration.php and take a look inside:
->enumNode('frontend')
->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom'))
->isRequired()
VichUploaderBundle is not a "frontend" bundle. It just provides a way to handle uploads and persist them in entities/models.
You can use VichUploaderBundle or OneupUploaderBundle but not both. However, you should be able to use any frontend you want (dropzone, FineUploader, MooUpload, etc.), it will just require a bit of integration work.

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