How to display the 404 error page in Symfony2 dev environment - symfony

I want to work on the 404 page from the dev environment. I customize 404 using this file : app/Resources/TwigBundle/views/Exception/error.html.twig
This prod url work correctly : mysite.com/404
But this one mysite.com/app_dev.php/404 throw a NotFoundHttpException and give me the dev debug page.
Is it possible to display the error page instead of debug page ?
UPDATE:
The official documentation has now a chapter about that : Testing Error Pages during Development

To display error pages, in web/app_dev.php change second parameter to false
$kernel = new AppKernel('dev', false);
After testing what you need, change it back.
UPDATE
Thanks #user2019515 for pointing that out - now (2.3 and up) there's a link to WebfactoryExeptionsBundle in Symfony docs and the method I wrote above should not be used.

As of Symfony2.6 in dev environment, you can use the following route:
/_error/404.html
Where 404 is the error code to test and html the format of the request.
To be able to use this features, make sure you have the following entry in your routing_dev.yml file:
# app/config/routing_dev.yml
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error

You need to override the exception_full.html.twig template on development.
app/Resources/TwigBundle/views/Exception/exception_full.html.twig
Symfony2 uses this template to provide you with as much debugging information as possible during development.
When the kernel is in debug mode, Symfony2 will use exception_full.html.twig, otherwise it will use the specific templates you override.
See vendor/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php, specifically the showAction() and findTemplate() functions for more details.

Also you can add routes to your routing_dev.yml file
error404:
path: /404
defaults:
_controller: FrameworkBundle:Template:template
template: TwigBundle:Exception:error404.html.twig
error500:
path: /500
defaults:
_controller: FrameworkBundle:Template:template
template: TwigBundle:Exception:error500.html.twig

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

how to config the OneupUploaderBundle?

I am trying to config the OneupUploaderBundle. According to the documentations in
github, the given config is:
oneup_uploader:
mappings:
gallery:
frontend: blueimp # or any uploader you use in the frontend
For this config, I got this error:
Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_uploader_upload_gallery" as such route does not exist.") in "MinnAdsBundle:Motors:oneup.html.twig" at line 25.
I tried to solve this issue by adding this config (as mentionned in github) to become like this:
oneup_uploader:
mappings:
gallery:
frontend: blueimp # or any uploader you use in the frontend
resource: .
type: uploader
The obtaind error is:
InvalidConfigurationException: Unrecognized options "resource, type" under "oneup_uploader"
So, I am wondering what I have missed in the config of this bundle.
For your information, The version I installed in my symfony project is:
"oneup/uploader-bundle": "1.3.1"
Thank for your help.
The documentation states the following:
To enable the dynamic routes, add the following to your routing configuration file.
# app/config/routing.yml
oneup_uploader:
resource: .
type: uploader
The correct place to put this is not the config.yml file but the routing.yml file instead.

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

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