Created
May 16, 2012 09:18
-
-
Save rsmarshall/2709003 to your computer and use it in GitHub Desktop.
search methods
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 | |
// Controller method | |
public function search() | |
{ | |
$results = NULL; | |
if ($this->input->get_post('search_string')) | |
{ | |
$results = $this->suppliers_model->search($this->limit, $this->input->get('per_page')); | |
$this->pager['base_url'] = current_url() . '?search_string=' . $this->input->get_post('search_string'); | |
$this->pager['total_rows'] = $results['count']; | |
$this->pager['per_page'] = 1; | |
$this->pager['page_query_string'] = true; | |
$this->load->library('pagination', $this->pager); | |
} | |
Template::set('results', $results['data']); | |
Template::set('search_string', $this->input->get_post('search_string')); | |
Template::set('toolbar_title', 'Search Feeds'); | |
Template::set_view('/content/search'); | |
Template::render(); | |
} | |
//model method | |
/** | |
* Search supplier feeds | |
* @param integer $limit | |
* @param integer $offset | |
* @return array returns an array with the search data and a total count | |
*/ | |
public function search($limit = NULL, $offset = NULL) | |
{ | |
$this->suppliers_model->set_table(FALSE); | |
$search_string = $this->input->get_post('search_string'); | |
$where = "supplier_code LIKE '%" . $search_string . "%' OR sku LIKE '%" . $search_string . "%'"; | |
$count = $this->count_by($where); | |
$this->db->join('supplier_details', 'supplier_pricing.supplier_id = supplier_details.id', 'left'); | |
if ($limit) | |
{ | |
$this->db->limit($limit, $offset); | |
} | |
$results = $this->find_all_by($where); | |
$this->suppliers_model->set_table(); | |
return array( | |
'data' => $results, | |
'count' => $count | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment