代码之家  ›  专栏  ›  技术社区  ›  Sanjok Gurung

Symfony 4条令,从数据库表创建实体

  •  0
  • Sanjok Gurung  · 技术社区  · 8 年前

    这里是Symfony的新成员 我正在跟踪 this 关于将db表映射到实体的教程。我创建了 blog_post blog_comment 数据库中的表。 我试过运行这个 php bin/console doctrine:mapping:import --force AppBundle xml 这会导致以下错误。

    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? 
    

    我的 doctrine.yaml 几乎是开箱即用。

    教条亚马尔

    doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
    
        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: true
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
    

    我创建了应用程序。php类位于 src/Entity/ 并在下面添加了一行 bundles.php 但仍然会出错。我在束上添加的行。php是 App\Entity\App::class=>['all' => true], 因为这是我的应用程序定义的命名空间。php类。

    我得到的另一个错误是

    PHP Fatal error:  Uncaught 
    Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load 
    class "App" from namespace "App\Entity\App".
    Did you forget a "use" statement for another namespace? in 
    /var/www/html/quick_tour/src/Kernel.php:32
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   pedram shabani    8 年前

    您必须在Symfony 4上使用应用程序而不是AppBundle

        2
  •  1
  •   Sanjok Gurung    8 年前

    发现类似情况 here

    因为Symfony 4使用App而不是Appbundle