Last active
December 25, 2015 04:39
-
-
Save lolautruche/6918631 to your computer and use it in GitHub Desktop.
Pagination in eZ Publish 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\TestBundle\Controller; | |
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; | |
use Pagerfanta\Pagerfanta; | |
use Symfony\Component\HttpFoundation\Response; | |
use eZ\Bundle\EzPublishCoreBundle\Controller; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier; | |
use eZ\Publish\API\Repository\Values\Content\Query; | |
class DefaultController extends Controller | |
{ | |
public function myContentListAction() | |
{ | |
$query = new Query(); | |
$query->criterion = new ContentTypeIdentifier( 'folder' ); | |
$pager = new Pagerfanta( | |
new ContentSearchAdapter( $query, $this->getRepository()->getSearchService() ) | |
); | |
// Let's list 2 folders per page, even if it doesn't make sense :) | |
$pager->setMaxPerPage( 2 ); | |
// Defaults to page 1 or get "page" query parameter | |
$pager->setCurrentPage( $this->getRequest()->get( 'page', 1 ) ); | |
return $this->render( | |
'AcmeTestBundle::my_template.html.twig', | |
array( | |
'totalFolderCount' => $pager->getNbResults(), | |
'pagerFolder' => $pager | |
) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends noLayout ? viewbaseLayout : "eZDemoBundle::pagelayout.html.twig" %} | |
{% block content %} | |
<h1>Listing folder content objects: {{ totalFolderCount }} objects found.</h1> | |
<div> | |
<ul> | |
{% for folder in pagerFolder %} | |
<li>{{ ez_content_name( folder ) }}</li> | |
{% endfor %} | |
</ul> | |
</div> | |
<div class="pagerfanta"> | |
{% if pagerFolder.haveToPaginate() %}{{ pagerfanta( pagerFolder, 'twitter_bootstrap_translated') }}{% endif %} | |
</div> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment