Vegas CMF Paginator

Vegas\Paginator\Adapter\AggregateMongo

AggregateMongo pagination adapter uses AggregateCursor to fetch data from mongo aggregation pipeline, hydrating objects from current page result set.

Minimal configuration

namespace Foo\Controllers\Frontend;

use Vegas\Mvc\Controller\ControllerAbstract;

class FooController extends ControllerAbstract
{
    public function indexAction()
    {
        $results = new \Vegas\Paginator\Adapter\AggregateMongo([
            'db' => $this->mongo,
            'modelName' => '\Foo\Models\Foo', // or 'model' => new FakeModel()
            'query' => [
                // aggregation pipeline here
            ]
        ]);

        $this->view->page = $results->getPaginate();
    }
}


If not specified, the default elements limit for pagination is 10.


Full configuration

namespace Foo\Controllers\Frontend;

use Vegas\Mvc\Controller\ControllerAbstract;

class FooController extends ControllerAbstract
{
    public function indexAction()
    {
        $results = new \Vegas\Paginator\Adapter\AggregateMongo([
            'db' => $this->mongo,
            'modelName' => '\Foo\Models\Foo', // or 'model' => new FakeModel()
            'limit' => 12,
            'page' => $this->request->get('page', 'int', 1),
            'query' => [
                // aggregation pipeline here
            ]
        ]);

        $this->view->page = $results->getPaginate();
    }
}


The query array is used by MongoCollection::aggregateCursor() For more details check method reference here.