Created
July 20, 2012 15:21
-
-
Save bakura10/3151298 to your computer and use it in GitHub Desktop.
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
// 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