【问题标题】:pagination of image in codeignitercodeigniter中图像的分页
【发布时间】:2014-09-30 00:58:00
【问题描述】:

我无法在图片库中进行分页..我是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;
    }

【问题讨论】:

    标签: codeigniter pagination


    【解决方案1】:

    在您的控制器中执行此操作

        $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?>
    

    希望它能为您节省很多时间

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      相关资源
      最近更新 更多