AppBundle symfony 4

試著忘記壹切 提交于 2019-12-13 22:38:57

问题


I have a problem with Symfony 4, I want generate entities from an existing database with the command :

php bin/console doctrine:mapping:import --force AppBundle xml

But an error appears :

Bundle "AppBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your App\Kernel.php file?

I try to import in the file kernel.php in registerBundles() :

new AppBundle/AppBundle();

but undefined class and when I create it in src/AppBundle/AppBundle.php :

<?php namespace AppBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class AppBundle extends Bundle { }

nothing change and when I retry the command :

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "AppBundle" from namespace "App". Did you forget a "use" statement for another namespace? in /var/www/html/symfony/Mission3/src/Kernel.php:30

I would like to know if it's possible to create a bundle like that or if it exists an other command to generate entities from an existing database.


回答1:


in SF4, The main application component is named 'App' by default and is not a bundle. You have to manually create a dummy bundle under src\ directory in order to use old doctrine:command related to bundle. see how to manually create a bundle here

After that, you can import/generate mappings/entities using doctrine:commands and use them in the App main module space, or in those bundles.

The SF4 maker tool don't provide bundle creation yet ... But I suppose the SF4 developers consider it's not an urge must have requirement, because they want us to focus on putting most code in the bundle less App main module.




回答2:


In symfony 4 'AppBundle' is doesn't exist anymore. Try use 'App' instead 'AppBundle'



来源:https://stackoverflow.com/questions/49498788/appbundle-symfony-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!