How can I display a Codeigniter 3 pagination as JSON? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How can I display a Codeigniter 3 pagination as JSON? (/showthread.php?tid=74234) |
How can I display a Codeigniter 3 pagination as JSON? - Ajax30 - 08-31-2019 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? RE: How can I display a Codeigniter 3 pagination as JSON? - milengardev1994 - 08-31-2019 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! |