how to config the OneupUploaderBundle? - symfony

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.

Related

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

Error While Updating Symfony2 Project

I'm trying to inject a Google Analytics tracking number into all my Symfony2 views so I used the instructions here http://symfony.com/doc/current/cookbook/templating/global_variables.html using this method:
# app/config/config.yml
twig:
globals:
ga_tracking: "%ga_tracking%"
And then I added my tracking number to parameters.yml
# app/config/parameters.yml
parameters:
ga_tracking: UA-xxxxx-x
And everything works perfectly but as soon as I do a composer.phar update or install I get the following message:
You have requested a non-existent parameter "ga_tracking".
And the ga_tracking line in my parameters.yml file gets erased (along with a couple other variables I've defined using the same process).
Any help would be appreciated.
The parameters.yml file is edited by Composer upon update, there's actually a comment about this at the top of the file...
# This file is auto-generated during the composer install
If you want to store additional parameters, store them elsewhere. In your config.yml, add a custom parameters file to your current imports :
imports:
- { resource: parameters.yml }
- { resource: my_parameters.yml } # Your custom file.
- { resource: security.yml }
Once you've made the edit, add your variables/parameters into a my_parameters.yml file instead. This one should be left untouched when updating. Don't forget to specify the parameters group in your custom file as well :
my_parameters.yml
parameters:
ga_tracking: "Your-tracking-code"
#ga_tracking: "%ga_tracking%"

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

Symfony 2 multiple bundles annotation type routing

I have a Symfony 2.3.1 application with two bundles. Each bundle contains Resources/config/routing.yml configuration file:
mobile:
resource: "#MyMobileBundle/Controller"
type: annotation
and
admin:
resource: "#MyAdminBundle/Controller"
type: annotation
This is app/config/routing.yml:
_mobile:
resource: "#MyMobileBundle/Resources/config/routing.yml"
prefix: /mobile
_admin:
resource: "#MyAdminBundle/Resources/config/routing.yml"
prefix: /admin
And app/config/routing_dev.yml contains:
_main:
resource: routing.yml
The problem is that each time only /admin/... or /mobile/... paths are available. If only one routing resource included in app/config/routing.yml everything works fine. Has anybody had such problem? Is it correct to set prefixes for different bundles this way?
The command php app/console router:debug is the best way to debug routes in Symfony2.
According to the details you provided everything seems to be correct and you are saying that removing one of the route prefix "fixes" your issue.
Visualizing your routes in an array
_mobile: # defines the prefix /mobile
mobile: # key that defines how you include your controller's route
main: /mobile/main # "main" is the route name which is duplicated below
_admin: # defines the prefix /admin
admin: # key that defines how you include your controller's route
main: /admin/main # this route override the original "main" route
In Symfony2 a route isn't defined by the addition of the prefix name and the route name but solely by the route name. If you have two routes named main then Symfony2 will only have reference of one.
In the case above, only /admin/main will be accessible because it overrode /mobile/main.
In short, you can't have two routes with the same route name.
So the best solution to fix the example above is by prefixing the route name with a key (much like namespacing):
_mobile:
mobile:
mobile_main: /mobile/main
_admin:
admin:
admin_main: /admin/main
Now you have two routes named admin_main and mobile_main which don't overlap each other.

How to display the 404 error page in Symfony2 dev environment

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

Resources