Skip to content

Instantly share code, notes, and snippets.

@hubertperron
Created June 23, 2014 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubertperron/1f6a11e75a558ccc9dab to your computer and use it in GitHub Desktop.
Save hubertperron/1f6a11e75a558ccc9dab to your computer and use it in GitHub Desktop.
Unifik controller with APYDatagrid example
<?php
/**
* Lists all Allergen entities.
*
* @return Response
*/
public function listAction()
{
$source = new Entity('AlikiSystemBundle:Allergen');
$tableAlias = $source->getTableAlias();
$locale = $this->getRequest()->getLocale();
$source->manipulateQuery(function($query) use ($tableAlias, $locale){
/** @var $query QueryBuilder*/
$query->resetDQLPart('join');
$query->leftJoin($tableAlias . '.translations', '_translations', 'WITH', $query->expr()->orX(
$query->expr()->eq('_translations.locale', ':locale'),
$query->expr()->isNull('_translations.id')
));
$query->setParameter('locale', $locale);
});
$grid = $this->get('grid');
// Attach the source to the grid
$grid->setSource($source);
$rowAction = new RowAction('Edit', 'aliki_system_backend_allergen_edit');
$rowAction->setRouteParameters(['id']);
$rowAction->setRouteParametersMapping(['id' => 'allergenId']);
$grid->addRowAction($rowAction);
// Manage the grid redirection, exports and the response of the controller
return $grid->getGridResponse('AlikiSystemBundle:Backend/Allergen/Allergen:grid.html.twig');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment