Php 如何转换为json原则关联ArrayCollection

Php 如何转换为json原则关联ArrayCollection,php,json,doctrine-orm,slim,Php,Json,Doctrine Orm,Slim,我有以下协会 class User { .... /** * @OneToMany(targetEntity="UserNote", mappedBy="user", fetch="EAGER") */ public $userNote; .... } class UserNote implements { .... /** * @ManyToOne(targetEntity="User", inversedBy="userNote") * @JoinColumn(name="id_u

我有以下协会

class User
{
....
/**
 * @OneToMany(targetEntity="UserNote", mappedBy="user", fetch="EAGER")
 */
public $userNote;
....
}
class UserNote implements
{
 ....
/**
 * @ManyToOne(targetEntity="User", inversedBy="userNote")
 * @JoinColumn(name="id_user", referencedColumnName="id_user")
 */
public $user;
....
}
当我选择一个用户时,上面的关联会生成以下objetc,该用户有一些UserNote:

App\Models\Entity\User Object
(
[id] => 4
[name] => Filipe Rodrigues
[email] => filipe@email.com.br
[login] => master
[password] => *********
[date] => DateTime Object
    (
        [date] => 2016-05-04 00:00:00.000000
        [timezone_type] => 3
        [timezone] => UTC
    )

[lastLogin] => DateTime Object
    (
        [date] => 2017-08-09 11:45:38.000000
        [timezone_type] => 3
        [timezone] => UTC
    )

[numLogin] => 161
[fone1] => 1112345678
[fone2] => 
[cep] => 09112000
[adress] => Rua Sila NAlon Gonzzaga
[cpf] => 289.233.498-52
[typeUser] => 3
[facebook] => 
[site] => 
[plan] => 
[idPlan] => 1
[note] => 
[fl_vip] => 
[fl_trial] => 0
[fl_cob] => 0
[recorrenceCode] => 0566AEA4DADA9861147E5F95DD2AF24B
[billingDay] => 13
[status] => 8
[token] => 
[parent] => 
[userNote] => Doctrine\ORM\PersistentCollection Object
    (
        [snapshot:Doctrine\ORM\PersistentCollection:private] => Array
            (
                [0] => App\Models\Entity\UserNote Object
                    (
                        [id] => 1
                        [note] => teste
                        [date] => DateTime Object
                            (
                                [date] => 2018-01-02 00:00:00.000000
                                [timezone_type] => 3
                                [timezone] => UTC
                            )

                        [user] => App\Models\Entity\User Object
 *RECURSION*
                    )

            )
......
因此,当我使用json_encode时,我得到以下结果:

{
"id": 4,
"name": "Filipe Rodrigues",
"email": "filipe@vitrinekar.com.br",
"login": "master",
"password": "ndtidis@23",
"date": {
    "date": "2016-05-04 00:00:00.000000",
    "timezone_type": 3,
    "timezone": "UTC"
},
"lastLogin": {
    "date": "2017-08-09 11:45:38.000000",
    "timezone_type": 3,
    "timezone": "UTC"
},
"numLogin": 161,
"fone1": "1112345678",
"fone2": null,
"cep": "09112000",
"adress": "Rua Sila NAlon Gonzzaga",
"cpf": "289.233.498-52",
"typeUser": 3,
"facebook": null,
"site": null,
"plan": null,
"idPlan": 1,
"note": null,
"fl_vip": null,
"fl_trial": 0,
"fl_cob": 0,
"recorrenceCode": "0566AEA4DADA9861147E5F95DD2AF24B",
"billingDay": 13,
"status": 8,
"token": null,
"parent": null,
"userNote": {}
}
userNote没有转换,如何使用json_encode转换条令关联


有人能帮我吗?

你试过使用Symfony的序列化程序组件吗?如果不看一看,我会尝试并张贴在这里的结果。谢谢@Yulioalemanjimenez您可以尝试$value[“userNote”]=$value[“userNote”]->toArray()@是的,这是一种方法,但是当我有一个用户对象数组时,我不能迭代数组用户对象来转换userNote。我只想返回结果。@YulioAlemanJimenez它与symfony一起工作!谢谢