我是codeigniter的新手,我想在我的桌子上应用分页。我按照教程,但在视图中看不到我的分页。我的表已有六行数据。我成功获得了所有数据,但分页无效。
这是我的控制器代码:
class news_cont extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library("pagination");
$this->load->helper('url');
$this->load->model('Post_newspaperjob_model','pnm');
}
public function index()
{
$this->load->library("pagination");
$config['base_url'] = base_url().'news/news_cont/index';
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['total_rows'] = $this->db->get('pp_jobcategories')->num_rows();
$this->pagination->initialize($config);
$data['query'] = $this->db->get('pp_jobcategories',$config['per_page'],$this->uri->segment(3));
$this->load->view('newspapers/news',$data);
}
}
我的型号代码:
public function getallcategories()
{
$query = $this->db->query('select * from pp_jobcategories');
return $query->result();
}
我的观看代码:
<?php
foreach($query->result() as $row){
echo "<p>" . $row->j_name . "</p>";
}
?>
<?php echo $this->pagination->create_links(); ?>