Controller subdirectories? - symfony

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

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.

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.

Symfony 2 multiple apps?

This appears to be the scariest topic relating to Symfony2, as after a week of searching and testing, I am still unable to find an answer to this.
In short, I am building an application that will have several subdomains, and I would like a different configuraton for all of them, while sharing multiple bundles from /src, and more importantly, import central config and routes (As well as each app's own)
I went down the road of creating individual /app directories, AppKernal.php files and bootstrap files. The main issue with this is detailed in another question, which has recieved no answers (not that I blame anyone TBH :D).
Symfony2 multiple config and routing files for subdomain routing
I have found discussion on the matter, Fabian even takes part in this:
https://groups.google.com/forum/?fromgroups=#!topic/symfony-devs/yneojUuFiqw
And this discussion on a PR to github to provide support in version 2.2 (still 6mo away I hear)
https://github.com/symfony/symfony/pull/3378
Is there anyone out there who has done this before? Is the process easy enough to explain? Is there any information available to assist with this?
I'm pretty much at the stage where it appears this simply is not possible. Which I find really strange for a system as touted as Symfony, especially when it appears Symfony1.4 did this rather easily.
Update
Thanks for your responses. The challenge is, there is a hierarchy of configs. These configs in turn import their own routing.yml files.
For instance: the domain http://testing.api.mydomain.com would include the following configs:
config_api.yml -> config_testing.yml -> config_dev.yml -> config.yml
All import their own routing.yml file. But only the one in config_api.yml is loaded. It seems framework: router: config option overrides previous usages in other config files, rather than extends.
In all fairness, the location of the app code is inconsequential. Having a hierarchical configuration with hierarchical routes seems to be the gotacha.
Cheers
Multiple applications projects can be achieved by splitting your code in multiple Kernels.
You can then benefit:
multiple web roots (useful for differents domains)
shared & specific config (via imports)
clean separation of Bundles...
I have described the whole process here: http://jolicode.com/blog/multiple-applications-with-symfony2 and you can find an example distribution here: https://github.com/damienalexandre/symfony-standard
Sorry for necroing...
I just want to say that I have looked into multiple application structure for Symfony2 as well. Since version 2.4, when routing supported hostname based routing, there has been no need for multiple apps.
All you now need to do is separate your "apps" into different bundles, say AcmeSiteBundle and AcmeApiBundle, then in app/config/routing.yml:
acme_site:
host: "www.{domain}"
resource: "#AcmeSiteBundle/Resources/config/routing.yml"
prefix: /
defaults:
domain: "%domain%"
requirements:
domain: "%domain%"
acme_api:
host: "api.{domain}"
resource: "#AcmeApiBundle/Resources/config/routing.yml"
prefix: /
defaults:
domain: "%domain%"
requirements:
domain: "%domain%"
Remember to have domain parameter set in app/config/parameters.yml
parameters:
.....
domain: example.com
You can create different configuration using the testing/Dev example :
Step 1
Create as many web/app.php file as you have subdomain.
web/app_subdomainx.php
Step 2
In each app_subdomain_X.php file change configuration :
$kernel = new AppKernel('subdomainx', false);
Step 3
create configuration file matching your environment
config_subdomainx.yml
security_subdomainx.yml
Step 4
acces you specific domain through
/web/app_subdomainx.php
PS :
Keep config.yml for common configuration (like db connection) and include config.yml into config_subdomainx.yml
imports:
- { resource: config.yml }
you can try to find something on github. I've found the following Bundle which should do this. Imikay RouterBundle
Basically Fabien is right, there's no reason to have more than one application, if you really have a need for a different application it's probably a different project. Bundles and libraries can be easily shared like any other bundle you see on the web.
Then you can have the small part of the set up belonging to each thing you call "app" in the app part of each project.
If they share the entirety of the code then it's just a matter of configuration hierarchy for each sub-domain, which could be your case considering you want to share some part of the config.
Symfony has many ways of allowing you to reutilise code which are very nice, but the framework is not meant to have many applications, if you want to try to hack it, go ahead, but then you're not using the framework anymore. And that's why you can't find examples, not because it's scary, it'd not be that hard to modify, it'd just be ugly, IMO.
Maybe you can try this bundle, that handle multiple domain website on same app and database:
https://github.com/AppVentus/MultiDomainBundle.

Resources