-
-
Save djoo/b2a5110ea66d272a3eaf to your computer and use it in GitHub Desktop.
Good practices with external content rooting
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 Djoo\MyBundle\Controller; | |
use eZ\Bundle\EzPublishCoreBundle\Controller; | |
use eZ\Publish\API\Repository\Values\Content\Location; | |
use Pagerfanta\Adapter\ArrayAdapter; | |
use Pagerfanta\Pagerfanta; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
use Djoo\MyBundle\Entity\MyEntity; | |
class ExempleFrontController extends Controller | |
{ | |
public function indexAction($locationId, $viewType, $layout = false, array $params = array()) | |
{ | |
$response = new Response(); | |
$response -> setSharedMaxAge(86400); | |
$response -> headers -> set('X-Location-Id', $locationId); | |
$response -> setVary('X-User-Hash'); | |
$repository = $this -> getRepository(); | |
$location = $repository -> getLocationService() -> loadLocation($locationId); | |
$content = $repository -> getContentService() -> loadContentByContentInfo($location -> getContentInfo()); | |
$filterBuilder = $this->get('doctrine.orm.entity_manager')->getRepository('Djoo%yBundle:Exemple')->createQueryBuilder('e')->orderBy('e.titre', 'asc'); | |
if ($this->get('request')->query->has($form->getName())) { | |
$form->submit($this->get('request')->query->get($form->getName())); | |
} | |
$query = $filterBuilder->getQuery(); | |
$exemples = $query->getResult(); | |
$adapter = new ArrayAdapter($exemples); | |
$pager = new Pagerfanta($adapter); | |
$pager->setMaxPerPage(isset($parameters['limit']) ? $parameters['limit'] : $this->container->getParameter( 'djoobase.blog.blog_post_list.limit' )); | |
$pager->setCurrentPage( $this->get('request')->get('page', 1) ); | |
$maxPerPage = $pager->getMaxPerPage(); | |
$nbResults = $pager->getNbResults(); | |
$currentPageResults = $pager->getCurrentPageResults(); | |
return $this -> render('DjooMyBundle:ExempleFront:rubrique_exemple.html.twig', | |
array('location' => $location, | |
'content' => $content, | |
'form' => $form->createView(), | |
'pager'=>$pager | |
), $response); | |
} | |
} |
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
system: | |
fre: | |
location_view: | |
full: | |
rubrique_nomenclature: | |
controller: "DjooMyBundle:ExempleFront:index" | |
template: "DjooMyBundle:ExempleFront:rubrique_exemple.html.twig" | |
match: | |
Id\Location: [906] |
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
exemple_show: | |
path: /Exemple/SubExemple/{slug} | |
defaults: { _controller: DjooMyBundle:ExempleFront:show } |
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 "DjooMyBundle::pagelayout.html.twig" %} | |
{% block content %} | |
<h1 class="titleInterior">{{ ez_field_value( content, 'titre' ) }}</h1> | |
<h2>{{pager|length()}} {{'résultats'|trans}}</h2> | |
{% if pager.haveToPaginate() %} | |
<div class="pagination-centered"> | |
{{ pagerfanta( pager, 'twitter_bootstrap_translated' ) }} | |
</div> | |
{% endif %} | |
{% if pager|length() > 0 %} | |
<ul> | |
{% for item in pager %} | |
<li><a href="{{ path('exemple_show', { 'slug': item.getSlug }) }}" alt="{{ item.getTitre }}">{{ item.getTitre }} </a></li> | |
{% endfor %} | |
</ul> | |
{% endif %} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment