在控制器Symfony2的自定義查詢
return $this->render(
'FrontBundle:Default:search.html.twig',
array(
'edition' => $edition, THIS ONE
'paginator' => $pagination,
'array_ed_id' => $editions_search,
'array_he_id' => $heading_search,
'text' => $text,
'seo' => $seo,
'result' => $result,
'testix' => 10
)
);
在枝杈
我需要自定義查詢value.getCount數行
{% for value in edition %}
<label><label class="" for="front_form_edition_s_{{ value.getId }}">
{{ value.getName }}</label>{{value.getCount}}</label>
在版實體
我添加自定義功能:
use Doctrine\ORM\Query\ResultSetMapping;
..........................
class Edition {
..........................
public function getCount()
{
$rsm = new ResultSetMapping();
$query = $entityManager->createNativeQuery('select count(*) from advert_edition where edition_id= ?', $rsm);
$query->setParameter(1, '16');
$users = $query->getResult();
return 10;
}
}
但這不起作用! :(請告訴我,我怎麼能做到這一點
問題在哪裏? – yunandtidus
他缺少方法調用的方括號。 – pcm
我認爲在實體內部進行查詢是錯誤的。對於我來說,你必須執行'{{value.advertEdition | length}}'或者在你的entityRepository中創建一個自定義方法。 –