-
Filtering and sorting data
Hello! I'm a beginner with Zend Framework.
I created a page to list the records of a table.
the sort code works but the filter seems to be ... unexecuted but i don't know why...
this is the PHP code for the controller:
public function listAction()
{
//prende il form dei filtri
$listToolsForm = new Form_BugReportListToolsForm();
$listToolsForm->setAction('/bug/list');
$listToolsForm->setMethod('post');
$this->view->listToolsForm = $listToolsForm;
$sort = $this->_request->getParam('sort', null);
$filterField = $this->_request->getParam('filter_field', null);
$filterValue = $this->_request->getParam('filter');
if (!empty($filterField)) {
$filter[$filterField] = $filterValue;
}
else{
$filter=null;
}
$listToolsForm->getElement('sort')->setValue($sort);
$listToolsForm->getElement('filter_field')->setValue($filterField);
$listToolsForm->getElement('filter')->setValue($filterValue);
$bugModels = new Model_Bug();
$adapter = $bugModels->fetchPaginatorAdapter($filter, $sort);
$paginator = new Zend_Paginator($adapter);
//$paginator = Zend_Paginator::factory($array);
$paginator->setItemCountPerPage(10);
$page = $this->_request->getParam('page', 1);
$paginator->setCurrentPageNumber($page);
$this->view->paginator = $paginator;
}
and this is for the model
public function fetchBugs($filters = array(), $sortField = null, $limit = null, $page=1){
$select = $this->select();
if (count($filters) > 0) {
foreach($filters as $field => $filter){
$select->where($field . ' =?', $filter);
}
}
if (null != $sortField) {
$select->order($sortField);
}
return $this->fetchAll($select);
}
thank you for your help...!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules