通过ajax分页并在同一页面上显示帖子

时间:2013-04-06 08:01:40

标签: ajax cakephp controller pagination cakephp-2.0

我是Cakephp的新手,我坚持这件事。 我的代码工作正常,但现在我需要在我的代码中进行一些修改。 当我尝试通过不同的页面对我的视图进行分页时,它可以正常工作,但每个页面只能获取20个帖子,以查看下一个帖子我更改了页面。 现在第一篇20篇帖子在我看来,点击一个按钮使用ajax我想在同一页面上显示下一篇20篇文章(我不想重新阅读页面以查看所有评论) 请帮忙......

这是我调用以显示不同页面视图的操作。

        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');
}

1 个答案:

答案 0 :(得分:0)

前几天我也在寻找ajax的分页。

经过长时间的搜索,我找到了一个解决方案,我在下面提到的链接中发布了这个解决方案。

Ajax pagination with filters in cakephp

相关问题