Doctrine entity object to array

前端 未结 8 680
星月不相逢
星月不相逢 2020-12-16 13:10

Wants to convert doctrine entiry object to normal array, this is my code so far,

 $demo = $this->doctrine->em->find(\'Entity\\User\',2);
         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-16 14:13

    If you alread have the object entity fetched form the database, you could also work with the DoctrineModule\Stdlib\Hydrator\DoctrineObject.

    /**
     * Assume your entity for which you want to create an array is in $entityObject.
     * And it is an instance of YourEntity::class.
     */
    $tmpObject = new DoctrineObject($this->entityManager, YourEntity::class);
    $data = $tmpObject->extract($entityObject);
    

    Now $data will contain your object as array.

    P.S. I'm not sure this was possible when the question was asked.

提交回复
热议问题