According to the CI official documentation it's possible to set preferences in a config file, but I can't get this to work.
I think I have narrowed the issue down to line 3 of my pagination.php file - the error message I receive is;
Message: Undefined property: CI_Loader::$db
Message: Call to a member function get() on null
Whenever I change this line of code from;
$config['total_rows'] = $this->db->get('item')->num_rows();
to
$config['total_rows'] = 200;
Everything works as expected. Am I failing to load something or call the database?
My code is:
Controller
public function index() {
$this->load->library('pagination');
$data = array(
'items' => $this->items_model->itemList(),
'title' => 'Library Items'
);
$this->load->view('item_list', $data);
}
Model
public function itemList() {
$this->db->select('item_id, item_title');
$this->db->from('item');
$this->db->limit(5, $this->uri->segment(3));
return $this->db->get()->result();
}
View
<?php echo $this->pagination->create_links() ?>
pagination.php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = '/ci/items/index';
$config['total_rows'] = $this->db->get('item')->num_rows();// when I change this to `$config['total_rows'] = 200` it works
$config['per_page'] = 5;
$config['num_links'] = 5;
$config['full_tag_open'] = '<div><ul class="pagination">';
$config['full_tag_close'] = '</ul></div><!--pagination-->';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$config['anchor_class'] = 'follow_link';
Thanks