0

I am new to Cakephp, and I m stuck with this thing. my code is working properly but now i need some modification in my code. when I try to paginate my view through different pages it works but as each page fetch 20 posts only, to see the next posts i change the page. Now the 1st 20 post is in my view and on the click of a button using ajax i want to show the next 20 post on the same page (I don't want to redirct to pages to see all the comment) plz help...

this is the action that i call to show the view of different pages.

        public function view($slug) {

    $topic = $this->Topic->getBySlug($slug);
    $user_id = $this->Auth->user('id');
    $post_count = $topic['Topic']['post_count'];


    $this->paginate['Post']['conditions'] = array('Post.topic_id' => $topic['Topic']['id']);

    if ($this->RequestHandler->isRss()) {
        $this->set('posts', $this->paginate('Post'));
        $this->set('topic', $topic);
        return;
    }

    if (!empty($this->request->data['Poll']['option'])) {
        $this->Topic->Poll->vote($topic['Poll']['id'], $this->request->data['Poll']['option'], $user_id);
        $this->Topic->deleteCache(array('Topic::getBySlug', $slug));
        $this->redirect(array('plugin' => 'forum', 'controller' => 'topics', 'action' => 'view', $slug));

    }

    $this->ForumToolbar->markAsRead($topic['Topic']['id']);
    $this->Topic->increaseViews($topic['Topic']['id']);

    $this->ForumToolbar->pageTitle($topic['Topic']['title']);
    $this->set('topic', $topic);
    $this->set('posts', $this->paginate('Post'));

    $this->render('view_new');
}
3
  • Your question doesn't show what you're trying inside the 'View' and doesn't show the JavaScript for the AJAX? Have a look at this question, it may be an answer: stackoverflow.com/questions/9328621/…
    – thaJeztah
    Apr 6, 2013 at 8:08
  • sir i dont know what to write in the Ajax to make that work. i need the ajax of this.
    – Jpm
    Apr 6, 2013 at 8:17
  • StackOverflow is not meant to have others write your code for you (read the faq). The other answer includes a link to the manual: AJAX Pagination, which may do what you want to do. In any case, you should really try to learn JavaScript, jQuery to get started.
    – thaJeztah
    Apr 6, 2013 at 8:24

1 Answer 1

0

I was also looking for ajax pagination few time ago.

After a long search i found a solution, which i have posted at the link mentioned below.

Ajax pagination with filters in cakephp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.