I'm trying to get a twig filter that would sort entities by score. My City class got a score attribute with getters and setters, and I created this extension :
<?php
namespace AOFVH\HomepageBundle\Twig;
use Twig_Extension, Twig_SimpleFilter, Twig_Environment;
class ScoreExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
$filter = new Twig_SimpleFilter('score', array('AOFVH\FlyBundle\Entity\City', 'getScore'))
);
}
public function getName()
{
return 'score_extension';
}
}
which I call like this :
{% for cit in cities|score %}
<a href="{{ path('aofvh_city', {'name': cit.name}) }}">
<div class="col-lg-4 col-md-12" style="margin-bottom:10px;">
<img src="{{ asset('Cities/'~cit.name~'.png') }}" class="img" alt="Cinque Terre" width="300" height="300">
<h2>{{cit.name}}</h2>
</div>
</a>
{% endfor %}
But for some reason, I cannot get it rendered, instead I git this error
ContextErrorException: Runtime Notice: call_user_func_array() expects parameter 1 to be a valid callback, non-static method AOFVH\FlyBundle\Entity\City::getScore() should not be called statically
Did I miss something ?