Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.1.x] Added new feature for pagination and also optional sets the aliases #10985

Closed
wants to merge 2 commits into from

Conversation

KorsaR-ZN
Copy link
Contributor

Maintain compatibility with version 2.0.x
see #10957

$repository = new \Phalcon\Paginator\Repository();
$repository->setAliases(array(
    'myFirstPage' => $repository::PROPERTY_FIRST_PAGE,
    'myLastPage' => $repository::PROPERTY_LAST_PAGE,
    'myCurrentPage' => $repository::PROPERTY_CURRENT_PAGE
));

$paginator = new \Phalcon\Paginator\Adapter\NativeArray(array(
    'data' => array_fill(0, 30, 'banana'),
    'limit'=> 25,
    'page' => 1,
    'repository' => $repository
));

$page = $paginator->getPaginate();

// First page
echo $page->first . PHP_EOL; // compatibility with version 2.0.x
echo $page->getFirstPage() . PHP_EOL; // Getter
echo $page->firstPage . PHP_EOL; // Magic getter
echo $page->myFirstPage . PHP_EOL; // Alias

// Current page
echo $page->current . PHP_EOL; // compatibility with version 2.0.x
echo $page->getCurrentPage() . PHP_EOL; // Getter
echo $page->currentPage . PHP_EOL; // Magic getter
echo $page->myCurrentPage . PHP_EOL; // Alias

// Last page
echo $page->last . PHP_EOL; // compatibility with version 2.0.x
echo $page->getLastPage() . PHP_EOL; // Getter
echo $page->lastPage . PHP_EOL; // Magic getter
echo $page->myLastPage . PHP_EOL; // Alias

@andresgutierrez
Copy link
Contributor

Why introduce a new class?

@KorsaR-ZN
Copy link
Contributor Author

@andresgutierrez This can be useful for the type-hinting:
In order not to transmit the paginator fully in function, but only a concrete state

function renderPage(\Phalcon\Paginator\RepositoryInterface $page) 
{
    //...expr...
}

//...expr...

$page = $paginator->getPaginate();
$pageRendred = renderPage($page);

//...expr...

or eg for serialization concrete page to transfer anywhere

@sergeyklay
Copy link
Contributor

@KorsaR-ZN The 2.1.x branch is best place for this

@Green-Cat
Copy link
Contributor

This is already targeting 2.1.x. It does need to be rebased though.

@sergeyklay
Copy link
Contributor

Oh, yes. Could you please rebase?

@sjinks sjinks closed this Apr 26, 2017
@sjinks sjinks reopened this Apr 26, 2017
@sergeyklay
Copy link
Contributor

ping @KorsaR-ZN

@niden
Copy link
Member

niden commented Dec 12, 2018

@KorsaR-ZN @CameronHall Thank you both. This has been addressed/cherry-picked in

#13653

@niden niden closed this Dec 12, 2018
@niden niden added 4.0 new feature request Planned Feature or New Feature Request breaks bc Functionality that breaks Backwards Compatibility labels Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks bc Functionality that breaks Backwards Compatibility new feature request Planned Feature or New Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants