简体   繁体   中英

Where are setters/getters when using YAML/XML mapping for Doctrine in Symfony?

在Symfony2中,当添加映射信息以告诉Doctrine如何将我的实体映射到数据库时,如果我使用YAML或XML格式而不是PHP注释,那么如何/在何处编写getters / setters /其他函数?

you can define mapping in yml or xml and still define entity class methods in the .php


Symfony Docs

Symfony docs show the metadata as annotations directly inside the Product class (option #1 PHP) at a different location src/AppBundle/Entity/Product.php than alternative (option #2 YAML and #3 XML) src/AppBundle/Resources/config/doctrine/Product.orm.*ml . This suggests that you can define the mapping in *ml and the getters/setters/other functions in the php .

Notice in the docs example the AppBundle\\Entity\\Product is specified in both files. The class methods and mapping can be defined independently and related to each other as AppBundle\\Entity\\Product .


Stackoverflow

Also note, this other question is misleading. You DO have to write getters/setters even if you use YAML/XML, as this answer clarifies:

Doctrine requires private/protected properties, so you'll still be writing getters and setters. And you'll still be writing the mapping info, just in another place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM