We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to use Resultset filter in volt

I need user function filter in Resultset of model http://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Resultset_Simple.html But i don't know how to write callback function in volt.

Please help me. Thank.


Volt does not support anonymous functions, but you can still use PHP there:

$filtered = $robots->filter(function($robot){
    if ($robot->id < 3) {
        return $robot;

{% for robot in filtered %}{{ robot.name }}{% endfor %}

inb4: I would be great that Volt supports anonymous functions

edited Jul '14


Thank for help but I can't use this way in my case

In controller i use Paginator


use Phalcon\Paginator\Adapter\Model as Paginator;

$paginator = new Paginator(array(
        "data" => $cats,
        "limit" => $limit,
        "page" => $numberPage


And use in views:

{% for index,cat in page.items %} {{ cat.posts.filter({'status=published'}) | length }} {% endfor %}

Thank for help.