[英]pagination links not working 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
您错过了$config
uri_segment
并更改了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]);
}
}
采用
'base_url'=> base_url('testimonials/index'),
也许这与URL重写有关。
先检查一下
http://localhost/lalcoresidency/index.php/testimonials
正在工作。
如果是这样,请看一下config.php:
$config['index_page'] = 'index.php';
如果您启用了mod_rewrite并且想要更清晰的URL(例如您提供的URL),则必须将上述变量设置为''并配置.htaccess,如下所示:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
希望这可以帮助!
采用
'base_url'=> base_url() . 'testimonials/index/',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.