CodeIgniter加载更多评论结果

问题描述 投票:0回答:1

任何人都可以帮助我为主题内容的评论结果更多地加载或进行分页?这是它的工作原理我的主题内容现在使用slug调用查询我希望通过pagenation或通过加载更多按钮显示主题内容回复

我的主题内容控制器:

 public function topic($slug = NULL) {

        // get single topic
        $data['item'] = $this->topic_model->getTopic($slug);
        if(empty($data['item'])) {
            $data['title'] = lang_key('404errorheader');
            $data['desc'] = lang_key('404errordesc');
            $this->load->view('themes/default/header', $data);
            $this->load->view('errors/html/error_404');
            $this->load->view('themes/default/footer');
        }else{ 

        $data['title'] = $data['item']['title'];
        $data['desc'] = strip_tags(word_limiter($data['item']['content'],30));

        $this->load->view('themes/default/header', $data);
        $this->load->view('threads/topic', $data);
        $this->load->view('themes/default/footer');
        $this->add_view($slug);
        }
    }

和我的主题内容模型:

 // get single topic
    public function getTopic($slug) {
        $query = $this->db->get_where('threads', array('thread_slug'=>$slug));
        return $query->row_array();
    }

和我的主题回复助手:

//get topic reply
if ( ! function_exists('get_topic_reply'))
{
    function get_topic_reply($topic_id)
    {

        $CI = get_instance();
        $CI->load->database();

        $CI->db->order_by('id', 'asc');
        $CI->db->where('topic_id',$topic_id);
        $CI->db->where('status',1);
        $query = $CI->db->get_where('threads_comment');
        return $query;

    }
}

这是我显示结果的方式。 mydomain / topic / topic-slug主题数据的内容是使用slug调用查询的主题内容,我只通过以下内容包含内容回复:

<?php require('topicreply.php');?>

这个主题的代码是reply.php:

                                   <?php 
                                    $topic_id = (isset($topic_id))?$topic_id:$item['id'];
                                    $topicreply = get_topic_reply($topic_id); 
                                    $i=0;
                                    foreach($topicreply->result() as $toprep):
                                    $i++;
                                    ?>

                                    <!-- .reply -->
                                    <div id="post-797" class="bbp-reply-header">
                                        <div class="bbp-meta">
                                            <span class="bbp-reply-permalink pull-right text-danger"><?php echo lang_key('reply'),' #'.$i ?></span>
                                        </div>
                                        <!-- .bbp-meta -->
                                    </div>
                                    <!-- #post-797 -->
                                    <div class="even topic-author hentry">
                                        <div class="bbp-reply-author">
                                            <a href="#" class="bbp-author-avatar">
                                                <img src="<?php echo get_profile_photo_by_id($toprep->user_id); ?>" class="avatar photo" alt="<?php echo get_user_title_by_id($toprep->user_id);?>" height="80" width="80">
                                            </a>
                                            <a href="#" class="bbp-author-name <?php echo get_user_type_by_id_name(get_user_role_by_id($toprep->user_id));?>"><?php echo get_user_title_by_id($toprep->user_id);?></a>
                                            <div class="bbp-author-role"><?php echo get_user_type_by_id(get_user_role_by_id($toprep->user_id));?></div>
                                            <div class="bbp-reply-post-date"><?php 
                                            $post_date = $toprep->created_at;
                                            $now = time();
                                            echo timespan($post_date, $now, 1).'&nbsp'.lang_key('ago'); ?>.</div>
                                        </div>
                                        <!-- .bbp-reply-author -->
                                        <div class="bbp-reply-content">
                                            <p><?php echo str_replace('href=', 'rel="nofollow" href=',$toprep->comment_content); ?></p>
                                        </div>
                                        <!-- .bbp-reply-content -->
                                    </div>
                                    <!-- .reply -->
                                    <?php endforeach ?>

我希望topicreply.php中的结果不会全部显示,而是会有一个加载更多按钮或pagenation。有人可以帮帮我吗?我一直在网上看,但我找不到类似于我的问题。

注意:代码工作正常,没有任何问题,我希望主题回复/评论可以通过pagenation或loadmore查看一些回复!

php ajax codeigniter
1个回答
1
投票

它现在正在工作,而不是加载更多我使用分页。这是我控制器中的代码

// category
    public function threadsview($slug=null, $offset=0) {
        // get threads category
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('pagination');

        $data['item'] = $this->threads_model->getThreadsCategory($slug);
        if($data['item']->num_rows()<=0){
            $data['title'] = lang_key('404errorheader');
            $data['desc'] = lang_key('404errordesc');
            $this->load->view('themes/default/layout/header', $data);
            $this->load->view('errors/html/error_404');
            $this->load->view('themes/default/layout/footer');
        }else
        foreach ($data['item']->result() as $res) {


        $data['title'] = $res->catname;
        $data['desc'] = $res->description;

        $cat_id = get_category_id_by_slug($slug);
        $total = 10; // total result x page

        // Config setup
        $num_rows = $this->threads_model->getAllThreadsPost($cat_id); // get all threads post per category
        $config['base_url'] = base_url().'threadsview/'.$slug;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $total;
        $config['num_links'] = $num_rows;
        $config['use_page_numbers'] = TRUE;
        $config['page_query_string'] = TRUE;
        $config['query_string_segment'] = 'page';
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&laquo;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';

        if ($this->input->get('page') != null) {
            $offset = ($this->input->get('page') - 1) * $config['per_page'];
        }

        $this->pagination->initialize($config);
        $data['threads_post'] = $this->threads_model->AllThreadsPost($cat_id, $config['per_page'], $offset);

        $this->load->view('themes/default/layout/header', $data);
        $this->load->view('threads/threadsview', $data);
        $this->load->view('themes/default/layout/footer');
        }
    }

但我有另一个担忧,我希望有人可以帮助我。结果编号是我的问题。正如您所看到的那样,分页将在每页显示10个结果,但是一旦您转到第二页我的结果编号,而数字将变为11到20,它将返回到1-10。看下面的代码

<?php if(count($threads_post) > 0){ ?>
                                                <?php 
                                                $i = 0;
                                                foreach($threads_post as $threads): 
                                                $i++;?>
© www.soinside.com 2019 - 2024. All rights reserved.