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 属性而不是注释?
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
