gpt4 book ai didi

php - Symfony 使 :entity annotation mapping error

转载 作者:行者123 更新时间:2023-12-02 00:05:59 36 4
gpt4 key购买 nike

我想使用 MakerBundle 中的 make:entity 命令在我的 ORO 平台应用程序中创建一个新实体。

我希望它在我的包 Acme\Bundle\TestBundle 中创建一个实体,我在 config_dev.yml 中使用以下方法设置了它:

maker:
root_namespace: 'Acme\Bundle\TestBundle'

所以我执行

bin/console make:entity Test

返回

 ! [NOTE] It looks like your app may be using a namespace other than "Acme\Bundle\TestBundle".                 
!
! To configure this and make your life easier, see:
! https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html#configuration

created: src/Acme/Bundle/TestBundle/Entity/Test.php
created: src/Acme/Bundle/TestBundle/Repository/TestRepository.php


[ERROR] Only annotation mapping is supported by make:entity, but the
<info>Acme\Bundle\TestBundle\Entity\Test</info> class uses a different format. If you would like
this command to generate the properties & getter/setter methods, add your mapping configuration, and then
re-run this command with the <info>--regenerate</info> flag.

我尝试再次运行该命令,成功了。但显然这不是它的工作方式。那么我该如何修复这个映射错误呢?

最佳答案

我使用 Symfony new myapp 从标准 Symfony 5 项目开始。

我在 config/packages/dev/maker.yaml 中添加配置文件

maker:
root_namespace: 'App\Core'

src/Core文件夹中生成实体,出现如下错误:

➜ symfony console make:entity Post

created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php


[ERROR] Only annotation mapping is supported by make:entity, but the <info>App\Core\Entity\Post</info> class uses
a different format. If you would like this command to generate the properties & getter/setter methods, add your
mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.

为了避免在控制台中显示错误,我安装了由 vklux/maker-bundle-force-annotation 创建的补丁

第一步:安装包

composer require cweagans/composer-patches

第 2 步:在 composer.json 中应用补丁

{
// {...} composer.json content
"extra": {
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}

第三步: Composer 更新

composer update

第 4 步:使用附加命令选项尝试 make:entity

➜ symfony console make:entity Post --force-annotation

created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php

Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.

New property name (press <return> to stop adding fields):
>

✅ 🚀 👍 现在一切正常。

关于php - Symfony 使 :entity annotation mapping error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60618554/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com