Doctrine findBy* methods and fetch array

后端 未结 4 750
孤街浪徒
孤街浪徒 2021-01-20 15:59

What is the cleanest way of using the Doctrine findBy methods but getting an array returned and not objects.

Doctrine::getTable(\'Table\')->findOneById(x)         


        
相关标签:
4条回答
  • 2021-01-20 16:41
    $adCampaign = $em->createQuery('select c from \Model\Campaign c where c.client = ?1')
    ->setParameter(1, $clientId)
    ->getArrayResult();
    

    where em is the entityManager - you get the result as array with getArrayResult

    0 讨论(0)
  • 2021-01-20 16:55

    Haim Evgi and DuoSRX's answers are correct, but there's a slightly different version for both that I prefer when using Symfony:

    Let's say your model name is Person, you would use:

    PersonTable::getInstance()->findOneById(x)->toArray();

    or

    PersonTable::getInstance()->findOneById($x, Doctrine_Core::HYDRATE_ARRAY);

    0 讨论(0)
  • 2021-01-20 16:57

    You can specify the hydration mode when using magic finders, like so:

    Doctrine_Core::getTable('Table')->findOneById($x, Doctrine_Core::HYDRATE_ARRAY);
    
    0 讨论(0)
  • 2021-01-20 17:05

    Try use toArray

    Doctrine::getTable('Table')->findOneById(x)->toArray();
    
    0 讨论(0)
提交回复
热议问题