简体   繁体   English

分页链接不工作codeigniter

[英]pagination links not working codeigniter

I am using the pagination class in my codeigniter application. 我在我的codeigniter应用程序中使用分页类。 The pagination links show up fine, ie, I suppose the right number of links eg. 分页链接显示正常,即,我想正确数量的链接,例如。 1 2 3 4 5 >, and the page loads up with the amount of entries I specified per page. 1 2 3 4 5>,页面加载了我每页指定的条目数量。

The error is when I click on one of the links to go to the next set of entries, it says "page cannot be found". 错误是当我点击其中一个链接转到下一组条目时,它显示“无法找到页面”。

controller 调节器

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]);
    }
}

model 模型

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();
    }
}

My website testimonial link is 我的网站推荐链接是

http://localhost/lalcoresidency/testimonials

You missed uri_segment in $config and change base_url as below. 您错过了$config uri_segment并更改了base_url,如下所示。 Try this 尝试这个

    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]);
    }
}

采用

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

Maybe this has something to do with URL rewriting. 也许这与URL重写有关。

first check if 先检查一下

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

is working. 正在工作。

If so, take a look at config.php: 如果是这样,请看一下config.php:

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

If you enabled mod_rewrite and you want cleaner URLs (like the one you provided) you have to set the above variable to '' and configure an .htaccess as follow: 如果您启用了mod_rewrite并且想要更清晰的URL(例如您提供的URL),则必须将上述变量设置为''并配置.htaccess,如下所示:

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

Hope this helps! 希望这可以帮助!

采用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM