Doctrine orm 条令2模型实体到关联数组
我不知道如何调用一个函数,该函数将执行以下操作:Doctrine orm 条令2模型实体到关联数组,doctrine-orm,Doctrine Orm,我不知道如何调用一个函数,该函数将执行以下操作: class Page { private $id; private $title; private $content; .. setters / getters } // Normal page object $page = $em->find('Page', 1); // What I need $page_as_array = array( 'id' => $page->getId(),
class Page {
private $id;
private $title;
private $content;
.. setters / getters
}
// Normal page object
$page = $em->find('Page', 1);
// What I need
$page_as_array = array(
'id' => $page->getId(),
'title' => $page->getTitle(),
'content' => $page->getContent()
);
// What I would like to type
$page_as_array = $page->asArray()
这可能吗?(我知道我可能可以为每个模型创建自己的asArray(),但为什么要重新发明轮子呢)