Symfony2 route not found order - symfony

I built a symfony2 project and I have a problem with my app/config/routing.yml. I have two routes for two bundles and only the last route can be resolved. If I change the order, still only last route can be resolved and for the first route I have an error message "No route found for "GET /collaborateur/". Any solutions?
This is my app/config/routing.yml:
front_office:
resource: "#FrontOfficeBundle/Resources/config/routing.yml"
prefix: /collaborateur
back_office:
resource: "#BackOfficeBundle/Resources/config/routing.yml"
prefix: /platform

First, it would be good to run router:debug in order to see which routes got loaded in fact.
php app/console router:debug
You should be able to see both of those here.
Secondly, I noticed that you sent a request to GET /collaborateur/. You might be hitting a known Symfony2 routing problem when it comes to trailing slash. It was described in this cookbook.
Can you try to open /collaborateur (without trailing slash)?

Related

Symfony 3.4. Not any route is working - No route found for "GET /

My Symfony 3.4 project does not recognize any route anymore. Debugging routes in terminal (php bin/console debug:router) does show all the routes but app_dev.php keeps giving error messages. Routing is enabled and set correct in routing.yml file.
Clearing cache also did not work.
mail_chimp:
resource: "#MailChimpBundle/Controller/"
type: annotation
prefix: /
/**
* #Route("/klanten/lijst")
*/
public function klantenLijstAction() {
return;
}
screenshot
Thanks.
> the routing tries to match routes one by one in the order of their definitions; whenever one matches, work is done.
In the routes-list image, you look to have three (maybe more) routes to answer the URL '/'. Which single one should run a controller action?
You should probably set prefixes for the URLs that aren't the index route.

Add optional _locale to routes

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

Symfony2 - integration of ckeditor and sonata media bundle

I am trying to integarte IvoryCKEditor with sonata media bundle. Perpose is to allow image uploads in ckeditor. I tried it using a CoopTilleulsCKEditorSonataMediaBundle but i keep getting an error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "admin_sonata_media_media_ckeditor_browser" as such route does not exist.") in "IvoryCKEditorBundle:Form:ckeditor_widget.html.twig".
Thanks :)
You should check your routes with the command:
$ php app/console debug:router | grep ckeditor
Then you have to replace admin_sonata_media_media_ckeditor_browser and admin_sonata_media_media_ckeditor_upload by routes founded with this command, in the config of ivory_ck_editor (maybe in your config.yml or your ivory_ckeditor.yml file)
If you don't have route for ckeditor, I think you should check if you install correctly the bundle.
1) install SonataFormatterBundle 2) add the bundle and its dependencies in AppKernel 3) config files 4) CLEAR CACHE 5) roll
Reason of the issue
This problem arises when trying to integrate CKEditor through the
SonataFormatterBundle without using the SonataAdminBundle.
In fact, the integration proposed by the SonataFormatterBundle is meant to only work for the SonataAdminBundle, and no easy integration for a custom admin bundle is currently available.
Note that this dependency is not specified in the documentation at the moment.
How to solve the problem
Simply install the SonataAdminBundle following this installation process. You do need to configure the bundle entirely as specified in the documentation. To add the routes that were missing, such as admin_sonata_media_media_ckeditor_browser, simply add the following to your config/routes.yml:
# This is your custom admin bundle
admin:
resource: "#AdminBundle/Controller/"
type: annotation
prefix: /admin/
# Import SonataAdminBundle routes
admin_area:
resource: "#SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin/sonata # put whatever prefix here
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
Just to add something.
If you are SURE that you have installed, all dependencies, and set all configs correctly, and still getting this error, then the cause may be that you have defined your 'sonata_media' prefix in routing.yml differently.
You can check all urls in your project in:
app/cache/dev/appDevUrlGenerator.php
In there you will find ALL routes in a variable $declaredRoutes
Afterwards simply put correct route name for browsing.
It will not work without SonataMediaBundle - you will need to install it with SonataFormatterBundle
Sonata become too complicated as for me, so I just use IvoryCKEditorBundle directly

FOSRestBundle doesn't load routes

I'm trying to make a REST API using FOSRestBundle and I'm getting some errors due to routing. This is how I test the routes. With this code in routing.yml I get this error:
1st test:
routing.yml
device_id_api:
type: rest
path: /device/{imei}/getid
resource: "Device\DeviceBundle\Controller\DeviceRestController"
Error
FileLoaderLoadException: Cannot import resource
"/var/www/html/src/Device/DeviceBundle/Resources/config/routing.yml"
from "/var/www/html/app/config/routing.yml". (The routing
file
"/var/www/html/src/Device/DeviceBundle/Resources/config/routing.yml"
must not specify both the "resource" key and the "path" key for
"device_id_api". Choose between an import and a route definition.)
2nd test:
`routing.yml
device_id_api:
type: rest
prefix: /device/{imei}/getid
resource: "TaxiBooking\Device\DeviceBundle\Controller\DeviceRestController"
Error
No route found for "GET /device/2147483647/getid"
What is wrong on that routes? I clear the cache several times and the error remains. Any help?
The prefix /device/{imei}/getid is exactly that, a prefix.
The actions in your controller like (for, example) getUsersAction will then be added to this prefix to create paths like /device/{imei}/getid/users [GET].
It's all explained in the docs minus your usage of the prefix, but that just means that it added to the start of the path auto-generated by the RoutingLoader.

Symfony2 CRUD routing Failed

After executing the following command for CRUD generation:
php app/console generate:doctrine:crud --entity=AcmeDemoBundle:Users --format=yml
i get error for automatic routing update by CRUD for each entity.
Confirm automatic update of the Routing [yes]? yes
Importing the CRUD routes: FAILED
The command was not able to configure everything automatically.
You must do the following changes manually.
- Import the bundle's routing resource in the bundle routing file
(C:\wamp\www\symfony\src\Acme\DemoBundle/Resources/config/routing.yml).
AcmeDemoBundle_categories:
resource: "#AcmeDemoBundle/Resources/config/routing/categories.yml"
prefix: /categories
I also tried creating a new bundle but still gets same error. So everytime i add the above code in routing file /src/Acme/DemoBundle/Resources/config/routing.yml
Can someone please suggest what i am missing?
I get the same thing, not sure how to get the generation to work right but it wants you to add that code to your main routing.yml file so it can link the generated routes:
AcmeDemoBundle_categories:
resource: "#AcmeDemoBundle/Resources/config/routing/categories.yml"
prefix: /categories

Resources