I am working on a small blogging application. There is a clear separation between its back-end and its front-end:
- The back-end is an [b]API[/b], made with Codeigniter 3, that spits out pages, posts, pagination etc.
- This API is consumed by an [b]AngularJS[/b] (v. 1.7.x) front-end;
The [b]front-end posts controller[/b] looks like this:
Code:
// All posts
.controller('PostsController', ['$scope', '$http', function($scope, $http){
//Get current page (?page=2, ?page=3 etc)
const currPage = window.location.search;
// Get all the posts on the current page
$http.get('api/' + currPage).then(function(response) {
// Posts
$scope.posts = response.data.posts;
// posts pagination
$scope.pagination = response.data.pagination;
});
}])
I have a problem with the pagination that Codeigniter (API) generates caused by the fact that its root is
Code:
http://apiblog.com/api/
. The pagination's HTML is this:
Code:
<ul class="pagination">
<li><a href="http://apiblog.com/api/" data-ci-pagination-page="1" rel="prev">‹</a></li>
<li><a href="http://apiblog.com/api/" data-ci-pagination-page="1" rel="start">1</a></li>
<li class="active"><span>2</span></li>
<li><a href="http://apiblog.com/api/?page=3" data-ci-pagination-page="3">3</a></li>
<li><a href="http://apiblog.com/api/?page=4" data-ci-pagination-page="4">4</a></li>
<li><a href="http://apiblog.com/api/?page=3" data-ci-pagination-page="3" rel="next">›</a></li>
</ul>
By looking at the front-end posts controller, you can see that the pagination links should [b]miss[/b] the api/ part. It [b]should[/b] be:
Code:
<ul class="pagination">
<li><a href="http://apiblog.com/" data-ci-pagination-page="1" rel="prev">‹</a></li>
<li><a href="http://apiblog.com/" data-ci-pagination-page="1" rel="start">1</a></li>
<li class="active"><span>2</span></li>
<li><a href="http://apiblog.com/?page=3" data-ci-pagination-page="3">3</a></li>
<li><a href="http://apiblog.com/?page=4" data-ci-pagination-page="4">4</a></li>
<li><a href="http://apiblog.com/?page=3" data-ci-pagination-page="3" rel="next">›</a></li>
</ul>
Given that the pagination items are generated "behind the scenes" by
Code:
$data['pagination'] = $this->pagination->create_links();
, I was unable to achieve the necessary configuration of the pagination links.
How can I achieve this?