You have a series of errors
- your count function in your model is missing parameters
- you should reformat the SQL string
- alternate and standard syntax in your view
- renamed model class to empty string
heres a fixed version,
Controller:
<?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');
}
public function _remap($a){
if (isset($a) && !empty($a)) {
switch ($a) {
case 'index':
$this->index();
break;
default:
$this->one_news($a);
break;
}
}
}
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,
'news' => $query);
$this->load->view('main/header');
$this->load->view('main/news', $data);
$this->load->view('main/footer');
}
}
Model:
// with default parameters just in case
function count_news($limit = 50, $offset = 0)
{
// and there is a nicer way to write your query
// it works with multiple dbs thanks to active record
$this->db->order_by('id','desc');
$query = $this->db->get('tdt_news', $limit, $offset);
return $query->result();
}