Vegas CMF Paginator

Vegas\Paginator\Adapter\Mongo

Mongo pagination adapter uses MongoCursor to fetch data and hydrate only objects from current page result set. Thanks to this solution it can be used with any amounts of data without memory usage issues.

Minimal configuration

namespace Foo\Controllers\Frontend;

use Vegas\Mvc\Controller\ControllerAbstract;

class FooController extends ControllerAbstract
{
    public function indexAction()
    {
        $results = new \Vegas\Paginator\Adapter\Mongo([
            'db' => $this->mongo,
            'modelName' => '\Foo\Models\Foo'
        ]);

        $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\Mongo([
            'db' => $this->mongo,
            'modelName' => '\Foo\Models\Foo',
            'limit' => 12,
            'page' => $this->request->get('page', 'int', 1),
            'query' => [
                'active' => 1
            ],
            'sort' => [
                'name' => -1
            ]
        ]);

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


The query array is used by MongoCursor::find() and the sort array is used by MongoCursor::sort(). For more details check MongoCursor reference here.