Codeigniter 分页不起作用 returns 404

Codeigniter pagination not worrking returns 404

您好,我需要一些帮助。我有两个控制器: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

问题是,当我尝试单击全景 link 以获取每个控制器中的下一条记录时,出现 404 错误。我试图在分页中更改我的配置设置,但没有成功。

如有任何帮助,我们将不胜感激。

$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;

我这里 link 对分页和排序很有帮助table table link这可能有帮助。

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