I'm having trouble finding the correct tutorial for me. I'm trying to have a controller-configuration in my bundle in Resources/config/someconfig.yml. I already adjusted it to a .yml extension. Now I'm searching a solution to access this configuration inside a twig exception controller (404-pages) and merge this configuration with the config.yml in app/config/.
Can anybody help me with a tutorial link or tips?
Thank you!
To get Resources/config/someconfig.yml config you can create DI extension: http://symfony.com/doc/current/cookbook/bundles/extension.html
I think this can help you to get configuration value in view: How to get config parameters in Symfony2 Twig Templates
As an alternative you can override Exception controller (get configuration parameters there and pass them to the view): http://symfony.com/doc/current/cookbook/controller/error_pages.html#replace-the-default-exception-controller
For merging configurations among independent bundles you should use prependExtensionConfig method and PrependExtensionInterface interface.
Documentaion page How to Simplify Configuration of multiple Bundles explains this technique in great detail.
Related
I'm starting to develop a project that will be quite big (hear lots of files) and I want to have an organization that's different from Symfony's default one: instead of having one dir for all my controllers, another for all my forms, etc, I want to have one dir per functionality, ie a directory for my homepage which will contain the controller, the templates, another dir for the blog page with the controller, forms and templates, and so on.
I tried what was explained in this (old) answer, and it didn't work : my routes weren't recognized, and a php bin/console debug:router showed they weren't listed anymore.
I feel I will have something to adapt in my routes.yaml file, which looks like this for now, and which explains why it doesn't work because it explicitely searches in the src\Controller directory:
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
I looked in the documentation I found, but I didn't find anything useful (I think I will have to remove the path and change it to something else, but I don't know what yet.
The above solutions are only for differentiating controller and template files. But For Entity, Events, and Forms it will not work.
It seems like you want to separate files for each module or functionality. For example, settings.yaml, controller, entity, forms, events, etc...
For that Symfony provides a Bundle feature. You can create a new Bundle in Symfony and use it as a separate feature. For more details please read this link
I want to load different configurations based on symfony route get parameter. For example following
GET www.xyz.com/{version}/someSlug
I want to read the version parameter and based on that want to load different configuration files, like the way its done in controllers. But in the AppKernel.php. Is it possible like that?
Any help or hint would be great.
Thanks
I'm trying to override the standard error.html.twig template provided by the Symfony2 Twig Bundle.
According to the docs, I just need to place a file error.html.twig in my app/Resources/TwigBundle/views/Exception folder and Symfony should use it.
I am able to specify specific error templates, like error404.html.twig, and those are used. But I'm looking to create a catch all template as well.
Anyone know what could be the issue?
The answer here seems to be clearing your cache after adding or editing your template.
A simple app/console cache:clear should resolve your problems also manually removing the app/cache directory should accomplish the same thing.
I created a bundle wjb/ImageBundle but I would like to load its routes without modifying app/config/routing.yml. From FOSRestBundle and few more, I see it is possible but I coudn't figure a way how to do that.
Is there some idiot-proof tutorial? I would like to use annotations but I would accept any other way too.
It's not possible to have routes in your application without registering them.
FOSUserBundle's routes can partly be defined in your security.firewalls configuration.
The others have to be imported as well described in the documentation chapter #6 - FOSUserbundle import routing files.
A workaround may be adding routes when loading a bundle without touching your routing.yml in a CompilerPass.
Should be simple enough. Everything works in my local environment, but not on my prod server (neither prod nor dev environment). I get an error that the FOS template cannot be found:
Unable to find template "FOSUserBundle::layout.html.twig".
My code is simple:
{% extends "FOSUserBundle::layout.html.twig" %}
I'm going from my local Windows machine to a Linux box. I've read case sensitivity might be the culprit, but it doesn't seem like it.
The FOS bundle is in the normal place: vendor/friendsofsymfony/user-bundle/FOS/UserBundle.
I'm having trouble diagnosing - any ideas? Did things get screwed up when I FTPd? Permissions issues? What are the common gotchas? I'm desparate!
Update: A clue. I ran assetic:dump and got
[RuntimeException]
".../app/Resources/FOSUserBundle/views/layout.html.twig" resource is hidden by a
resource from the "*******Bundle" derived bundle. Create a
".../app/Resources/*******Bundle/views/layout.html.twig" file to override the bundle
resource.
This question seems relevant.
Another update: I was using getParent() in my own bundle to override the templates. I switched to the first method in the docs but now the templates in app/resources simply aren't having an effect. It's going straight to the default form template with a white background.
Any ideas?
It was a upper/lower case/namespacing thing. I thought my local files were in sync with remotes but they were not.
Just check your whole directory & all namespaces in the FOS bundle!
I also encountered the problem and "solved" it by renaming my layout.html.twig inside my bundle's Resources/views folder to bundle-layout.html.twig and adapting my templates accordingly.
I resolved the resource is hidden by a resource error by moving the template in the good bundle extension.
Specifically from app/Resources/FOSUSerBundle/views/ChangePassword
to src/Application/Sonata/UserBundle/Resources/views/ChangePassword
I confounded FOSUser & SonataUser.