Created
June 23, 2014 14:44
-
-
Save hubertperron/1f6a11e75a558ccc9dab to your computer and use it in GitHub Desktop.
Unifik controller with APYDatagrid example
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 | |
/** | |
* 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