分页codeigniter不使用bootstrap

时间:2013-08-13 08:31:35

标签: php codeigniter pagination

我不知道为什么它不工作。我跟着很多文章,但似乎我的代码完全错了我需要删除所有东西。<< 1,2,3>>这个标志即将到来但是当我点击任何东西时,只有url chng不会发生任何其他事情。

这是我的控制器

function view($offset=0){
            $limit=5;
            //$this->uri->segment(3);
            $this->load->model('emp_expenses_model');
            //$result['contents']=$this->emp_expenses_model->getRows($limit,$offset);
            $result['countRows']=$this->emp_expenses_model->countRows();
            $this->load->library('pagination');
            $this->load->library('table');
            $config=array(
                            'base_url' =>site_url ('/view_expenses/view?'),
                            'total_rows' => $result['countRows'],
                            'per_page' => $limit,
                            'uri_segment' => 3,
                            //'num_links' => 200,
             );  
             //var_dump($config); 
            $this->db->limit('5');
            $this->pagination->initialize($config);
            $this->load->model('emp_expenses_model');
            $this->data['view_expenses'] = $this->emp_expenses_model->get_all();
            //$this->data['pagination'] = $this->pagination->create_links();
            //var_dump($this->data['pagination']);die("jk");
            $this->data['title'] = 'Payroll System';
            $this->data['message'] = $this->session->flashdata('message');
                $this->load->library('pagination');
            $this->load->view('view_expenses', $this->data);
            /*$this->load->view('add_list', $this->data);*/

        }       

这是我的模特

<?php
class Emp_expenses_model extends CI_Model
{
    function emp_expenses_model()
    {
        parent::__construct();
    }
    function get_all()
    {
        $this->db->select('expenses_id,id,dropdown,modeofpayment,amount');
        $query=$this->db->get('emp_expenses');

        return $query->result_array();
    }
    function get_record($list_id)
    {
        $this->db->select('expenses_id,id, dropdown, modeofpayment, amount');
        $this->db->where('id',$list_id);
        $query=$this->db->get('emp_expenses');

        return $query->result_array();

    }
    function insert_list($data)
    {
        $this->db->insert('emp_expenses', $data);
        $id = $this->db->insert_id();
        return (isset($id)) ? $id : FALSE;

    }

    public function update_list($list_id, $data)
    {
        $this->db->where('id', $list_id);
        $this->db->update('emp_expenses', $data);
    }

    public function del_list($list_id)
    {
        $this->db->where('id', $list_id);
        $this->db->delete('emp_expenses');
    }
    function getRows($limit,$offset)
    {
    $query=$this->db->select('expenses_id,id,dropdown,modeofpayment,amount')
           ->from('emp_expenses')
           ->limit($limit,$offset);
    $result=$query->get()->result_array();
    return $result;
    //var_dump($result);
    }
    function countRows()
    {
    //$query="select count(*) as count from emp_expenses";
    $result = $this->db->count_all_results('emp_expenses');
    //$result=$this->db->query($query);
    return $result;
    //var_dump('countRows');
}

并在视野中 * 在表格内写作 *

<?php echo $this->pagination->create_links()?>

2 个答案:

答案 0 :(得分:0)

试试这个,希望有所帮助:
编辑:

function view($offset=0){
    $limit=5;
    $this->load->model('emp_expenses_model');
    $countRows=$this->emp_expenses_model->countRows();
    $this->load->library('pagination');
    $this->load->library('table');
    $config=array(
                    'base_url' =>base_url('/index.php/view_expenses/view/'.$this->uri->segment(3)),
                    'total_rows' => $countRows,
                    'per_page' => $limit,
                    'uri_segment' => 3,
     );  
    $this->pagination->initialize($config);
    $this->data['view_expenses'] = $this->emp_expenses_model->getRows($limit,$this->uri->segment(3));
    $this->data['title'] = 'Payroll System';
    $this->data['message'] = $this->session->flashdata('message');
    $this->load->view('view_expenses', $this->data);
}

答案 1 :(得分:0)

控制器中的功能

function users(){
            if ($this->ion_auth->is_admin() && $this->ion_auth->logged_in()){   
                    $this->load->model('reciever');
                    $this->load->library('uri');
                    $this->load->library('pagination');
                    $config['base_url'] = base_url(). 'users_ci/users';
                    $config['total_rows'] = $this->reciever->getRows();
                    $config['per_page'] = 4;
                    $config['num_links']=2;
                    $config['users']= $this->reciever->getUsers(4,$this->uri->segment(3));
                    $this->pagination->initialize($config);
                    $config['pages'] = $this->pagination->create_links();
                    $this->load->view('users',$config);
             }else{
                 $this->load->view('login_form');
             }
      }

这是为了视图

   <?php echo $pages; ?>

您必须完全按照您希望在页面中看到的数量来查询您的数据库