Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created July 20, 2012 15:21
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 bakura10/3151298 to your computer and use it in GitHub Desktop.
Save bakura10/3151298 to your computer and use it in GitHub Desktop.
// In controller :
/**
* Show all the students
*
* @return array
*/
public function indexAction()
{
$studentService = $this->getStudentService();
$query = $this->request->getQuery();
$studentService->enableFilter($query);
$students = $studentService->getAll();
return array(
'students' => $students->setCurrentPageNumber(1)
);
}
// Service student :
/**
* Add a filter and enable it
*
* @param $params
* @return void
*/
public function enableFilter($params)
{
$config = $this->serviceManager->get('doctrine.configuration.orm_default');
$config->addFilter('student_filter', 'Application\Doctrine\Query\Filter\StudentFilter');
$filter = $this->getEntityManager()->getFilters()->enable('student_filter');
foreach ($params as $key => $value) {
$filter->setParameter($key, $value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment