分页链接不工作codeigniter

时间:2016-05-16 10:34:16

标签: php html codeigniter

我在codeigniter应用程序中使用分页类。分页链接显示正常,即,我想正确数量的链接,例如。 1 2 3 4 5>,页面加载了我每页指定的条目数量。

错误是当我点击其中一个链接转到下一组条目时,它说"页面找不到"。

控制器

class Testimonials extends CI_Controller{

    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->model('testimonial_model');
        $this->load->library('pagination');
    }

    public function index(){
        $config=[
            'base_url'          =>  base_url('lalcoresidency/testimonials'),
            'per_page'          =>  15,
            'total_rows'        =>  $this->testimonial_model->num_rows(),           
            'full_tag_open'     =>  "<ul class='pagination'>",
            'full_tag_close'    =>  "</ul>",
            'first_tag_open'     =>  '<li>',
            'first_tag_close'    =>  '</li>',
            'last_tag_open'     =>  '<li>',
            'last_tag_close'    =>  '</li>',
            'next_tag_open'     =>  '<li>',
            'next_tag_close'    =>  '</li>',
            'prev_tag_open'     =>  '<li>',
            'prev_tag_close'    =>  '</li>',
            'num_tag_open'      =>  '<li>',
            'num_tag_close'     =>  '</li>',
            'cur_tag_open'      =>  "<li class='active'><a>",
            'cur_tag_close'     =>  '</a></li>',
        ];
        $this->pagination->initialize($config);       
        $result=$this->testimonial_model->get_testimonial($config['per_page'],$this->uri->segment(3));        
        $this->load->view('testimonials_view',['result'=>$result]);
    }
}

模型

class Testimonial_model extends CI_Model{

    function get_testimonial($limit,$offset){
        $this->db->select('*');
        $this->db->from('testimonial');
        $this->db->order_by("r_id", "desc");
        $this->db->limit($limit,$offset);
        $query=$this->db->get();
        return $result=$query->result();
    }

    public function num_rows(){
        $this->db->select('*');
        $this->db->from('testimonial');
        $this->db->order_by("r_id", "desc");

        $query=$this->db->get();
        return $result=$query->num_rows();
    }
}

我的网站推荐链接

http://localhost/lalcoresidency/testimonials

4 个答案:

答案 0 :(得分:2)

您错过了uri_segment中的$config并更改了base_url,如下所示。试试这个

    class Testimonials extends CI_Controller{

    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->model('testimonial_model');
        $this->load->library('pagination');
    }

    public function index(){
        $config=[
            'base_url'          =>  base_url('testimonials/index'),
            'uri_segment'       => 3,
            'per_page'          =>  15,
            'total_rows'        =>  $this->testimonial_model->num_rows(),           
            'full_tag_open'     =>  "<ul class='pagination'>",
            'full_tag_close'    =>  "</ul>",
            'first_tag_open'     =>  '<li>',
            'first_tag_close'    =>  '</li>',
            'last_tag_open'     =>  '<li>',
            'last_tag_close'    =>  '</li>',
            'next_tag_open'     =>  '<li>',
            'next_tag_close'    =>  '</li>',
            'prev_tag_open'     =>  '<li>',
            'prev_tag_close'    =>  '</li>',
            'num_tag_open'      =>  '<li>',
            'num_tag_close'     =>  '</li>',
            'cur_tag_open'      =>  "<li class='active'><a>",
            'cur_tag_close'     =>  '</a></li>',
        ];
        $this->pagination->initialize($config);       
        $result=$this->testimonial_model->get_testimonial($config['per_page'],$this->uri->segment(3));        
        $this->load->view('testimonials_view',['result'=>$result]);
    }
}

答案 1 :(得分:1)

使用

'base_url'=>  base_url('testimonials/index'),

答案 2 :(得分:0)

这可能与URL重写有关。

首先检查是否

http://localhost/lalcoresidency/index.php/testimonials

正在运作。

如果是这样,请看一下config.php:

$config['index_page'] = 'index.php';

如果你启用了mod_rewrite并且你想要更清晰的URL(比如你提供的那个),你必须将上面的变量设置为''并配置.htaccess如下:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

希望这有帮助!

答案 3 :(得分:0)

使用

'base_url'=>  base_url() . 'testimonials/index/',