只想使用codeigniter为搜索结果添加分页,但在我的视图中看不到任何页码。请帮我找出错误。
这是我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Filter extends MX_Controller {
public function index() {
$this->load->view("view_filter");
}
public function search($offset = 0) {
$limit = 3;
$this->load->library('form_validation');
$this->load->model('model_filter');
$this->form_validation->set_rules('country', 'Country','required');
if($this->form_validation->run()) {
if ($results = $this->model_filter->did_filter($limit, $offset)){
$data['results'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
$this->load->library('pagination');
$config = array();
$config['base_url'] = site_url('filter/search/');
$config['total_rows'] = $data['num_results'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view("view_search_results",$data);
}
else {
$data['message'] = 'No listings are available yet.';
$this->load->view("view_no_search_results",$data);
}
}
else
{
$data['message'] = 'Please select your search options.';
$this->load->view("view_no_search_results",$data);
}
}
}
这是我的模特:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_filter extends CI_Model {
function __construct()
{
parent::__construct();
}
public function did_filter($limit, $offset) {
$this->db->select('*');
$this->db->from('table');
$this->db->where('country', $this->input->post('country'));
$this->db->limit($limit, $offset);
$query = $this->db->get();
if ($query && $query->num_rows() > 0) {
$return['rows'] = $query->result_array();
$return['num_rows'] = $query->num_rows();
return $return;
} else {
return false;
}
}
}
以下是我的观点:
<div><?php if (strlen($pagination)) {echo 'Pages:'. $pagination;} ?> </div>
<?php
foreach($results as $row){
$country = $row['country'];
echo $country; }
?>