CodeIgniter 分页错误生成下一个 link
CodeIgniter Pagination wrong generate next link
我退出新手并尝试在 Codeigniter 中进行分页...
我要用一个额外的参数创建分页.. link 第一个参数是为数据库搜索获取 ID.. 而不是创建分页...我已经完成了,但下一页 link不正确,因为它应该是。请检查我的代码,让我知道我在做什么错。
这是模型代码..
我的模特class 名字是 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();
}
这和控制器代码。
我的控制器 class 名称是 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 →';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_link'] = '< 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');
}
只需要在 Controller Function 的 pagination $config 数组中添加 uri_segment
...
$config['uri_segment'] = 4;
我退出新手并尝试在 Codeigniter 中进行分页... 我要用一个额外的参数创建分页.. link 第一个参数是为数据库搜索获取 ID.. 而不是创建分页...我已经完成了,但下一页 link不正确,因为它应该是。请检查我的代码,让我知道我在做什么错。
这是模型代码..
我的模特class 名字是 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();
}
这和控制器代码。
我的控制器 class 名称是 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 →';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_link'] = '< 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');
}
只需要在 Controller Function 的 pagination $config 数组中添加 uri_segment
...
$config['uri_segment'] = 4;