解決辦法: 使用getArrayResult 轉換為數組
存儲類 代碼
<?php
// src/AppBundle/Repository/ProductRepository.php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* 商品的自定義存儲類
*/
class ProductRepository extends EntityRepository
{
public function findAllOrderedByName()
{
return $this->getEntityManager()
->createQuery(
'SELECT p FROM AppBundle:Product p ORDER BY p.name ASC'
)->getArrayResult();
}
}
控制器代碼:
public function listAction(){
$products = $this->getDoctrine()
->getRepository(Product::class)
->findAllOrderedByName();
dump($products);
}
處理結果: