Symfony2 CRUD routing Failed - symfony

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

Related

Symfony2 route not found order

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)?

How to run a command when a Symfony2 project is online (production mode)

How can you run a command on a Symfony2 command when it is online? I see that you need a command window but my project is going to be ran at a server that isn't mine, so how can I run commands on it? My host provides directadmin.
You can use https://github.com/CoreSphere/ConsoleBundle
If you have the "no route" error, try to access to
yoursite/web/app_dev.php/_console/_console
as the prefix defined in your routing_dev.yml will be added to the path defined in the Bundle's routing.yml
routing_dev.yml
_console:
resource: "#CoreSphereConsoleBundle/Resources/config/routing.yml"
prefix: /_console
#routing.yml from ConsoleBundle
console:
path: /_console

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%"

Assetic Route Not Found

I have a twig extension whose purpose is to collect a list of CSS and JS file paths given to it by function calls throughout a template hierarchy and then at the end of the twig template to take the output buffer and include these files in the <head> section of the page. For the most part it has been straightforward to implement.
In my service definition for the twig extension I am injecting the assetic.helper.dynamic service into it. The problem is when I call the javascripts() or stylesheets() method to get a URL for a CSS or JS file I get an error like this:
An exception has been thrown during the rendering of a template ("None
of the chained routers were able to generate route: Route
'_assetic_bd311c7' not found")
service.yml:
admin.twig.asset_extension:
class: Zing\Delta\AdminBundle\Twig\AssetExtension
tags:
- { name: twig.extension }
arguments: ['#assetic.helper.dynamic']
In my extension I am essentially doing this to get the URL for an asset:
$assetic_helper->stylesheets(array(
'#SomeBundle/Resources/public/js/jquery.tablesort.min.js'
));
I don't understand why the router can't find the routes or why assetic is setting up the routes.
The fix ended up being to run the following commands in the following order from the project root.
$ php app/console assets:install
$ php app/console assetic:dump
$ php app/console cache:clear

Resources