3

在我的存储库类中,我有这个,但查询不起作用。

 public function getResultsByName($page, $resultsCount, array $request_arr){     
 $qb = $this->createQueryBuilder('xx'); 
 $qb->addSelect('SUM(xx.quantity) as total')
    ->leftJoin('xx.reception', 'x')
    ->addSelect('x')
    ->leftJoin('x.purchase', 'p')
    ->addSelect('p')
    ->leftJoin('p.provider', 'pr')
    ->addSelect('pr')
    ->where('pr.id = :company_id')
    ->setParameter('company_id', $request_arr['company_id']);

 $query = $qb->getQuery(); 

 return parent::getPaginator($query, $page, $resultsCount); }

错误出现在我的树枝模板中,这是其中的重要部分

    {% for result in results %}
<tr>
    <td>{{result.reception.id}}</td>
    <td>{{result.reception.date|date('d-m-Y')}}</td>
    <td>{{result.reception.purchase.id}}</td>
    <td>{{result.reception.purchase.provider.name|upper}} [{{result.reception.purchase.provider.id}}]</td>
    <td>{{result.purchaseProduct.name |upper}} [{{result.purchaseProduct.productCode |upper}}]</td>
    <td>{{result.purchasePrice}}</td>
    <td>{{result.quantity}}</td>
    <td></td>
    <td>{{result.quantityStock}}</td>
</tr>   
{% endfor %}
4

1 回答 1

3

由于您的查询有两个选择,因此您的结果对象是这样的数组:

array(
    'total' => $total,
    'xx' => array(
        'reception' => $reception,
        'quantityStock' => $quantityStock,
        [...]
    ) 
);

要在 twig 中访问您的属性,您必须像这样访问它:

{{result.xx.reception}}
{{result.total}}
于 2013-06-24T12:20:59.943 回答