【发布时间】:2015-04-20 18:39:16
【问题描述】:
您好,我需要一些帮助。我有两个控制器:movies.php 和 actor.php,我在其中列出了所有演员和其中的所有电影。
例如,这是列出我所有电影的方法
public function index() {
// count all movies
$total = $this->movie_model->count();
// set up pagination
$per_page = 10;
if ($total > $per_page) {
$this->load->library('pagination');
$config['base_url'] = site_url($this->uri->segment(1) . '/');
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$offset = $this->uri->segment(2);
}
else {
$this->data['pagination'] = '';
$offset = 0;
}
// fetch the movies
$this->db->limit($per_page, $offset);
$this->data['movies'] = $this->movie_model->get();
// load the view
$this->view('movies/index');
}
列出所有演员
public function index() {
// count all actors
$total = $this->actor_model->count();
// set up pagination
$per_page = 10;
if ($total > $per_page) {
$this->load->library('pagination');
$config['base_url'] = site_url($this->uri->segment(1) . '/');
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$this->data['pagination'] = $this->pagination->create_links();
$offset = $this->uri->segment(2);
}
else {
$this->data['pagination'] = '';
$offset = 0;
}
// fetch the movies
$this->db->limit($per_page, $offset);
$this->data['actors'] = $this->actor_model->get();
// load the view
$this->view('actors/index');
}
我的路线是这样设置的
$route['default_controller'] = "movies";
$route['404_override'] = '';
$route['movies'] = 'movies/index';
$route['actors'] = 'actors/index';
而且网址是这样的
h**p: //localhost/www/task/public/ // for movies (default controller)
h**p: //localhost/www/task/public/actors // for actors controller
问题是当我尝试单击 panination 链接以获取每个控制器中的下一个记录时,我收到 404 错误。我试图在分页中更改我的配置设置,但没有运气。
任何帮助将不胜感激。
【问题讨论】:
标签: php codeigniter pagination