我想在CodeignIter分页中添加一个下拉菜单,以便用户可以自己选择每页的项目。
但$ config ['per_page']的值不会改变。点击第2页后,我们会考虑默认值。
任何帮助我怎么能做到这一点。在将来我还想添加搜索和按名称排序到此网格。所以解决方案应该是合适的。
这是我的档案。
控制器:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class products extends CI_Controller {
public $ipp = 5;
public function __construct(){
parent::__construct();
$this->load->model('productmodel');
$this->load->helper(array('form', 'url'));
// $this->load->model(array('usermodel','categorymodel'));
}
public function index()
{
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/just4ad/index.php/products/index';
$config['total_rows'] = $this->db->count_all_results('jobs');
if(!empty($this->input->post('sel'))){
$this->ipp = $this->input->post('sel');
}
$config['per_page'] = $this->ipp;
$start = end($this->uri->segments);
$end = $config['per_page'];
if(empty($start) || $start == 1){
$start = 0;
}
$this->pagination->initialize($config);
$data['product_data'] = $this->productmodel->getAllProducts($end, $start);
$this->load->view('index', $data);
}
}
型号:
<?php
class productmodel extends CI_Model {
var $title = '';
var $content = '';
var $date = '';
function getAllProducts($limit = '',$start = '')
{
if($limit != '' && $start != '' && $start != 0){
$this->db->limit($limit, $start);
}else if($limit != '' && $start == 0){
$this->db->limit($limit);
}
$result = $this->db->get('jobs');
$data = $result->result_array();
return $data;
}
}
?>