我是 CI 的新手,我尝试了很多方法来运行它,但它仍然无法正常工作。你能告诉我我做错了什么吗?
所以,控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('model_add','',TRUE);
}
public function _remap($a){
if (isset($a) && !empty($a)):
switch ($a) {
case 'index':
$this->index();
break;
default:
$this->one_news($a);
break;
}
endif;
}
public function index()
{
$this->load->library('pagination');
$home=$this->uri->segment(2);
$limit=2;
$offset=0;
$query=$this->model_add->count_news($limit,$offset);
$config['base_url'] = base_url().'/news/';
$config['total_rows'] = $this->db->count_all('tdt_news');
$config['per_page'] = 2;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$data = array('query' => $query,'page'=>$home);
$data['news'] = $query;
$this->load->view('main/header');
$this->load->view('main/news', $data);
$this->load->view('main/footer');
}
}
和模型:
function count_news()
{
$query=$this->db->query("SELECT * FROM `tdt_news` ORDER BY `id` DESC LIMIT $limit, $offset;");
return $query->result();
}
我将非常感谢您的帮助,谢谢!