Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Extending Paginator Class

Hi,

Is it possible to extend \Phalcon\Paginator\Adapter\Model, so that I could add some feature on it? If yes, what is the better way to do this? I have following class in Library folder

<?php
namespace CustomShopping\Libraries\Paginator; // CustomShopping\Libraries is registered in bootstrap file

class Paginator extends \Phalcon\Paginator\Adapter\Model
{
  public function __construct(){
      parent::__construct();
  }

  public function customFunction(){
      return "Hello world";
  }
}
?>

And then in my controller i used it like

$paginator = new CustomShopping\Libraries\Paginator(
    array(
        'data'  => $users,
        'limit' => $limit,
        'page'  => $page,
    )
);

and in view i called it like,

$paginator->customFunction();

I get the error CustomShopping\Libraries\Paginator not found error. Thanks for the help



2.1k
Accepted
answer

Okay i have got it working myself

Pagination.php in library folder

use Phalcon\Paginator\Adapter\Model;

class Pagination extends \Phalcon\Paginator\Adapter\Model
{
    public function __construct(array $config){
        parent::__construct($config);
    }

    public function customFunction(){
        return "Hello world";
    }
}

and in controller i called it like

$pagination = new \Pagination();