2016-01-23 63 views
1

由於某種原因,我想將一個實體序列化爲一個簡單的key => value數組而不包含相關的實體以及數據庫中列的真實名稱。有沒有辦法開箱即用?或者我應該使一個實體序列化程序使用註釋來加載列名稱Symfony/Doctrine:如何將一個實體序列化到一個鍵值數組

+0

你可能如果屬性名稱,而不是列名是適合你使用標準的串行器組件。 –

回答

1

我相信這可能是您的解決方案的一部分。

$reader = new AnnotationReader(); 


    $fieldNames = $em->getClassMetadata('AppBundle:Entity')->getFieldNames(); 
    foreach($fieldNames as $field){ 
     $reflClass = new \ReflectionProperty('AppBundle\Entity\Entity',$field); 
     $classAnnotations = $reader->getPropertyAnnotations($reflClass); 

     var_dump($classAnnotations[0]->name); 
    } 

Doctrine\ORM\Mapping\Column Doctrine Annotations

相關問題