How can I display a Codeigniter 3 pagination as JSON? |
I am working on a blog application with Codeigniter 3.1.8.
Currently, its admin area is well separated from the frontend. In the frontend, I have managed to replace "classic" Codeigniter views with JSONS. (The JSONS are displayed and "handled" with AngularJS): Code: private function _initPagination($path, $totalRows, $query_string_segment = 'page') { What I have not been able to do (despite tormenting my brain), is display the pagination of the posts as JSON too. My pagination view: Code: <div class="pagination-container text-center"> I have tried Code: echo json_encode(['pagination' => $this->pagination->create_links()]); It does not work. What shall I do?
I don't think this will work out.
Code: $this->pagination->create_links() This code as far as I know only generates HTML template. I had a similar issue and I have created custom library that can output it as JSON object. To create the pagination you need the total pages count and amount of results per page. Code: $res['max_pages'] = ceil($totalImagesCount / MAX_RESULTS_PER_PAGE); This is some example code I have used. I hope I help you a bit! |
Welcome Guest, Not a member yet? Register Sign In |