CodeIgniter Pagination错误生成下一个链接

时间:2015-01-20 04:53:06

标签: php codeigniter pagination

我退出新并尝试在Codeigniter中制作分页...... 我用一个额外的参数创建分页..链接第一个参数是获取数据库搜索的ID ..而不是创建分页...到目前为止我做了但是下一页链接不正确它应该是。请检查我的代码,让我知道我在做什么。

这是型号代码.. 我的模型类名是movie

public function get_movies_by_actor($actor_id,$num=10,$start=0)
{
    $this->db->select(" f.film_id,
                        f.language_id,
                        a.actor_id,
                        f.title,
                        f.description,
                        l.name AS language,
                        c.name AS category,
                        concat(a.first_name, ' ', a.last_name ) AS actor_name
                    ",FALSE);
    $this->db->from('actor AS a');
    $this->db->join('film_actor AS fa', 'fa.actor_id=a.actor_id');
    $this->db->join('film AS f', 'f.film_id=fa.film_id', 'left');
    $this->db->join('language AS l', 'l.language_id=f.language_id', 'left');
    $this->db->join('film_category AS fc', 'f.film_id=fc.film_id', 'left');
    $this->db->join('category AS c', 'c.category_id=fc.category_id', 'left');
    $this->db->where('a.actor_id', $actor_id);
    $this->db->order_by('f.film_id','desc')->limit($start,$num);
    $query = $this->db->get();
    return $query->result();
}

这和控制器代码。 我的控制器类名是movies

public function actor_movie($actor_id,$start=0)
{
    $data['movies']=$this->movie->get_movies_by_actor($actor_id,$start,10);
    $this->load->library('pagination');
    $config['base_url'] = base_url().'index.php/movies/actor_movie/'.$actor_id.'/';
    $config['total_rows'] = $this->movie->get_total_movies();
    $config['per_page'] = 10;
    $config['display_pages'] = FALSE;
    $config['first_link'] = FALSE;
    $config['last_link'] = FALSE;

    $config['next_tag_open'] = '<li class="next">';
    $config['next_link'] = 'Older Post &rarr;';
    $config['next_tag_close'] = '</li>';

    $config['prev_tag_open'] = '<li class="prev">';
    $config['prev_link'] = '&lt Newer Post';
    $config['prev_tag_close'] = '</li>';

    $this->pagination->initialize($config); 

    $data['pagination_links'] = $this->pagination->create_links();
    $data['title'] = '$this->pagination->create_links()';

    $this->load->view('header');
    $this->load->view('actor_movies',$data);
    $this->load->view('footer');
}

1 个答案:

答案 0 :(得分:1)

只需要在Controller Function ...

中的pagination $ config数组中添加uri_segment
$config['uri_segment'] = 4;