Codeigniter分页不起作用返回404

时间:2015-02-19 12:08:39

标签: php codeigniter pagination

嗨,我想要一些帮助。我有两个控制器:movies.php和actors.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错误。我试图在分页中更改配置设置,但没有运气。

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

我在此链接非常有用,可以帮助分页和可排序的表链接。

http://forum.codeigniter.com/thread-1198.html

答案 1 :(得分:0)

$config['base_url'] = site_url($this->uri->segment(1) . '/');更改为

$config['base_url'] = base_url().'movies/index'; 

$config['base_url'] = base_url().'actors/index';

$config['uri_segment'] = 3;