In controller
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
)
);
in Twig i need custom query value.getCount to count rows
{% for value in edition %}
<label><label class="" for="front_form_edition_s_{{ value.getId }}">
{{ value.getName }}</label>{{value.getCount}}</label>
in Edition entity i add custom function:
use DoctrineORMQueryResultSetMapping;
..........................
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;
}
}
But this doesn’t work! 🙁 Please tell me how i can do that.
2
Answers
For this case i found another solution, i created twig extension Count
And in twig:
If you don’t have the “count” property in your object, then:
or if you have the count property and “getCount” is the only getter: