In twig.yaml I have definded global path:
paths:
'%kernel.project_dir%/public/assets/media': images
And now I would like to get this path (as a full real path) in one of my symfony class.
How can I do it?
Thank you.
You could inject Twig\Loader\FilesystemLoader in your service and get the path through $loader->getPaths('images'). The container builder should already have the paths resolved for you - does that help?
I am currently building my own Symfony bundle (I am using version 3.3). It works fine so far, but now I wanted to move the bundle-specific service definition out of my app/config/services.yml to a service definition within the bundle.
I created a src/MyBundle/Resources/config/services.yml and followed the guide How to Load Service Configuration inside a Bundle to load it. That works just fine, but I thought that the paths inside the newly created services.yml look a bit ugly:
MyBundle\:
resource: '../../*'
exclude: '../../{Tests}'
So I thought it would look a little cleaner, if I use the #Bundle-notation instead:
MyBundle\:
resource: '#MyBundle/*'
exclude: '#MyBundle/{Tests}'
However, than I was facing the error:
FileLocatorFileNotFoundException
The file "#MyBundle" does not exist (in: <...>\MyBundle\DependencyInjection/../Resources/config), where <...> corresponds to an absolute path.
I also tested whether it was a naming issue of the bundle name, but when I have a wrongly named bundle reference in the app/config/services.yml, e.g. #SomeBundleThatDoesNotExist then I get a different error:
FileLoaderLoadException
Bundle "SomeBundleThatDoesNotExist" does not exist or it is not enabled.
So my question is: Why does the #Bundle-notation work fine in the app/config/services.yml but not in the src/MyBundle/Resources/config/services.yml?
If you use the service remember make public for external use:
autowire: true
public: true
But, if your symfony dont know where is the bundle please chec this answer:
Symfony generated Bundle doesn't work
EDIT | I tried prefixing controllers class name with "Web" - no dice :(
According to everything I have read and previously experienced:
http://symfony.com/doc/current/best_practices/controllers.html
I should be able to move/organize controllers into sub-folders but now I cannot seem to get Symfony to cooperate:
AppBundle/Controller
- MemberController.php
- DefaultController.php
Works fine - but if I move
AppBundle/Controller
/web/MemberController
- DefaultController
Then clear the cache - I get the following error(s):
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Class AppBundle\Controller\MemberController does not exist in /var/www/project/src/AppBundle/Controller (which is being imported from "/var/www/project/app/config/routing.yml").
[ReflectionException]
Class AppBundle\Controller\MemberController does not exist
Of course it doesn't I moved it up down one directory into a sub-folder "web". What gives? My routing.yml is as simple as:
site:
resource: "#AppBundle/Controller"
type: annotation
I'm trying to override a vendor Twig extension,but I'm getting this error: Cannot redeclare class APY\DataGridBundle\Twig\DataGridExtension .
I have just copied the php from vendor to my bundle extension folder, rename the namespace to Acme\DemoBundle\Extension;
and then add this to my config.yml
parameters:
grid.twig_extension.class: Acme\DemoBundle\Extension\DataGridTwigExtension
following the directions from services override http://symfony.com/doc/current/cookbook/bundles/override.html
Any ideas to solve this? Thanks!
Just a naive problem, I needed to clear cache !
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