Skip to content

Instantly share code, notes, and snippets.

@djoo djoo/ExempleFrontController.php Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Good practices with external content rooting
<?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);
}
}
system:
fre:
location_view:
full:
rubrique_nomenclature:
controller: "DjooMyBundle:ExempleFront:index"
template: "DjooMyBundle:ExempleFront:rubrique_exemple.html.twig"
match:
Id\Location: [906]
exemple_show:
path: /Exemple/SubExemple/{slug}
defaults: { _controller: DjooMyBundle:ExempleFront:show }
{% 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
You can’t perform that action at this time.