Codeigniter and AngularJS bug: pagination does not work when the application is not in the root directory Codeigniter and AngularJS bug: pagination does not work when the application is not in the root directory codeigniter codeigniter

Codeigniter and AngularJS bug: pagination does not work when the application is not in the root directory


Take a look at this line:

$config = $this->_initPagination("/", $this->Posts_model->get_num_rows());

This specifies the path as "/", which is passed as $path, so in your function the link path will be

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . $path;

which will just put a / at the end of the root URL. You will need to pass the proper suffix at index instead of "/" when not on root.


The problem is here:

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . $path;

Because $_SERVER['HTTP_HOST'] is always the root without other directory.

You need to use something like:

$config['base_url'] = str_replace("/api/", "/", base_url()) . $path;

But I recomand you to implement the pagination in your front end (Angular) and in CI you need only something like:

public function index($offset, $limit) {    $data = [];    $data['count'] = $this->Posts_model->get_num_rows();    $data['pages'] = $this->Pages_model->get_pages();    $data['categories'] = $this->Categories_model->get_categories();      $data['posts'] = $this->Posts_model->get_posts($limit, $offset);    $this->output->set_content_type('application/json')->set_output(json_encode($data,JSON_PRETTY_PRINT));}