教义实体对象到数组

教义实体对象到数组

本文介绍了教义实体对象到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要将教义实体转换为普通数组,这是我目前的代码,

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

 $demo = $this->doctrine->em->find('EntityUser',2);

获取实体对象,

EntityUser Object
(
[id:EntityUser:private] => 2
[username:EntityUser:private] => TestUser
[password:EntityUser:private] => 950715f3f83e20ee154995cd5a89ac75
[email:EntityUser:private] => [email protected]
[firm_id:EntityUser:private] => EntityFirm Object
    (
        [id:EntityFirm:private] => 16
        [company_name:EntityFirm:private] => TestFirm
        [company_detail:EntityFirm:private] => India
        [created_at:EntityFirm:private] => DateTime Object
            (
                [date] => 2014-08-01 18:16:08
                [timezone_type] => 3
                [timezone] => Europe/Paris
            )

        [user:EntityFirm:private] =>
    )

[created_at:EntityUser:private] => DateTime Object
    (
        [date] => 2014-08-01 15:12:36
        [timezone_type] => 3
        [timezone] => Europe/Paris
    )

[updated_at:EntityUser:private] => DateTime Object
    (
        [date] => 2014-08-01 15:12:36
        [timezone_type] => 3
        [timezone] => Europe/Paris
    )

[firm:protected] =>
) ,

试过 这个 ,但根据我的requiremnet,不想使用doctrine_query.谢谢.

Tried this ,But as per my requiremnet do not want to user doctrine_query.Thanks.

推荐答案

你可以试试这样的,

    $result = $this->em->createQueryBuilder();
    $app_code = $result->select('p')
            ->from('YourUserBundle:User', 'p')
            ->where('p.id= :id')
            ->setParameter('id', 2)
            ->getQuery()
            ->getResult(DoctrineORMQuery::HYDRATE_ARRAY);

另一种方式,

 $this->em->getRepository('YourUserBundle:User')
      ->findBy(array('id'=>1));

上面将返回一个数组,但包含教义对象.返回数组的最佳方法是使用教义查询.

Above will return an array but contains doctrine objects. Best way to return an array is using the doctrine query.

希望这会有所帮助.干杯!

Hope this helps.Cheers!

这篇关于教义实体对象到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:14