Detect routes and entities from Symfony2 vendor - symfony

i'm creating a bundle that adds an entity and a few routes to be use in a Symfony2 application.
I want my bundle to be used as a vendor, so I've created all the files, published it on GitHub and packagist and everything works fine.
My problem is now when I require the bundle in another project, my entities and my routes are not detected:
1) php app/console doctrine:schema:update doesn't detect any modification
2) When I try to hit a GET route from the vendor, here is the error I get:
No route found for "GET ..."
Any idea is welcome, what's the process to really do these things in a bundle?
Cheers.
Cyril

Take a look at the installation steps of the FOSUserBundle for example. Everyone who uses your published bundle, have to activate it in the appkernel and import the routes. For the entity I think the bundle user have also to subclass the entity.

Related

Is there a way to move Symfony 6's controllers to several other directories?

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

in-vendor bundle controller autoload for use annotation

I have a problem with my project, I can't load my controller in my CoreBundle, but I manage it with Composer for updating easily in production server.
All code is on my github : https://github.com/super-vizor.
Supervizor (the main app) call CoreBundle by composer, but after update, during cache clear process, it gives an error:
"The file "../Controller" does not exist (in:
D:\Supervizor\supervizor\vendor\super-vizor\corebundle\DependencyInjection/../Resources/config)."
Why am I getting this error? How can I load my controller ?
Thanks for the response in advance and sorry for my English I'm French.

How do I automatically include routing and config.yml for bundles in /vendors

I've recently started separating out our custom bundles from our Symfony2 app so that they can be shared across multiple projects. I have successfully got them into their own repositories and included back into the main app via Composer. I know I have to register them in AppKernal, but I was hoping that I wouldn't have to link directly to their routing.yml and config.yml files from the ones in the /app/config/*.yml.
Is there a way to automatically include the config files from bundles within the vendors folder?
It turns out a colleague had done this before with config.yml pointed me to this documentation
http://symfony.com/doc/current/cookbook/bundles/extension.html#using-the-load-method
By adding the following to the load() function in your bundle's extension you can have it auto load the various configuration files
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
$loader->load('services.yml');
However this doesn't work with routing.yml because it thinks it has to load an extension matching the name of each route.
Please see my answer - https://stackoverflow.com/a/58140085/1274890
Also as per https://symfony.com/doc/current/bundles/override.html#routing
Routing is never automatically imported in Symfony. If you
want to include the routes from any bundle, then they must be manually
imported from somewhere in your application (e.g. config/routes.yaml).

Symfony2: add routes from my bundle

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.

Symfony cannot find template on prod server

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.

Resources