How can i use php8 attributes instead of annotations in doctrine?(我如何在学说中使用 php8 属性而不是注释?)
问题描述
这是我想使用的:
#[ORMColumn(type: "string")]
而不是这个:
/**
* @ORMColumn(type="string")
*/
但是我收到了这个错误:
But I'm getting this error:
(error: Class 'Column' is not annotated with 'Attribute' )
是因为 Doctrine 还不支持,还是我遗漏了什么?
Is it because Doctrine does not support it yet, or am I missing something?
推荐答案
正如@Seb33300 所说,是的,它是 现在可能.但是对于 Symfony,您需要做的还不止这些.以下是升级步骤的完整列表:
As @Seb33300 says, yes, it's now possible in Doctrine ORM 2.9. But for Symfony you need to do a little bit more than that. Here is a full list of steps to upgrade:
升级 Doctrine ORM:
doctrine/orm":^2.9"
.
升级 Doctrine Bundle:doctrine/doctrine-bundle":^2.4"
.
Upgrade Doctrine Bundle: "doctrine/doctrine-bundle": "^2.4"
.
设置doctrine.orm.mappings.App.type: attribute
(默认设置为annotation
):
# config/packages/doctrine.yaml
doctrine:
orm:
mappings:
App:
type: attribute
对您的实体应用类似的更改:
Apply similar changes to your entities:
--- Dummy.php.old Mon Jun 07 00:00:00 2021
+++ Dummy.php Mon Jun 07 00:00:00 2021
@@ -7,15 +7,11 @@
use AppRepositoryDummyRepository;
use DoctrineORMMapping as ORM;
-/**
- * @ORMEntity(repositoryClass = DummyRepository::class)
- */
+#[ORMEntity(repositoryClass: DummyRepository::class)]
class Dummy
{
- /**
- * @ORMId
- * @ORMGeneratedValue
- * @ORMColumn(type = 'integer')
- */
+ #[ORMId]
+ #[ORMGeneratedValue]
+ #[ORMColumn(type: 'integer')]
private $id;
}
这篇关于我如何在学说中使用 php8 属性而不是注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何在学说中使用 php8 属性而不是注释?


基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01