在codeigniter中的图像分页

时间:2014-08-06 22:38:43

标签: codeigniter pagination

我不能在图像gellery中进行分页..我是codeigniter的新人。可以有人写我这个的分页代码???? ____

controller-
public function gallery() {
    $data = array();
    $data['title'] = '। Gallery ।';
    $data['logo_image'] = $this->w_model->select_logo_image();
    $data['all_gallery_image'] = $this->w_model->select_all_gallery_image();
    $data['maincontent'] = $this->load->view('gallery', $data, true);
    $this->load->view('master', $data);
}    


model- 

   public function select_all_gallery_image() {
    $this->db->select('*');
    $this->db->from('image_gallery');
    $query_result = $this->db->get();
    $result = $query_result->result();
    return $result;
    }

1 个答案:

答案 0 :(得分:0)

控制器中的

执行此操作

    $this->load->library('pagination');
    $this->load->library('table');
    $count = $this->db->get('tablename')->num_rows();//it's just a short cut, you need to do this in your model
    $config['base_url'] = base_url() . "index.php/controllername/functionname";
    $config['total_rows'] = $count;
    $config['per_page'] = 8;//data showing perpage
    $config['num_links'] = 4;//number of links of pagination.. 
    //note: don't rename any key of your config, it will not run if you do
    $this->pagination->initialize($config);//initialize your pagination, 


    $data['record'] = $this->db->get('image_gallery',8,$this->uri->segment(3));
    //in this code, the 8 is the limit of data per page,
    //the uri-segment is the 3 address of url starting your controller name, 
    //for example if your url is like this  
    //localhost/ci/index.php/controllername/functionname
    //the uri segment it will get the third segment of your url, the count on url start in controllername/(2nd)functionname/(3rd)
    $this->load->view("your view",$data);
在您的视图中

之后

<?php 
echo $this->table->generate($record);//pass the record to table..and it will automatically create a table, the header of this table is the column name of your table

echo $this->pagination->create_links(); //this will create the link of your pagination?>
希望它能为你节省很多时间