Codeigniter Pagination显示链接但返回NO Data

时间:2018-03-23 09:29:23

标签: php codeigniter

如果我不包括分页i.a.注释掉$this->db->limit并删除$limit&来自$start方法的get_category_posts(),值会显示在表格中。但是,只要添加限制,就会显示链接,但不会显示'帖子'。我觉得分页设置或限制业务有问题,甚至可能是我所在的位置$this->db->limit(目前不足$this->db->from('posts')。我整夜都试着这样做工作并且在互联网上没有运气,大多数人似乎都有拖延链接而不是数据本身的问题。如果有人能指出我会非常感激的方向。谢谢。

MODEL:

public function get_category_posts($slug = FALSE, $limit, $start){
    if($slug === FALSE){
        $this->db->select('post_id, user_id_fk, post_title, post_content, post_date, slug, username');
        $this->db->join('category_link_table', 'posts.post_id = category_link_table.post_id_fk');
        $this->db->join('category', 'category_link_table.cat_id_fk = category.cat_id');
        $this->db->join('users', 'posts.user_id_fk = users.user_id');
        $this->db->from('posts');
        $this->db->limit($limit, $start);
        $this->db->where('category.parent_id', 0);
        $query = $this->db->get();

        foreach($query->result() as $row){
            $data [] = $row;
        }
        return $data;
        //return $query->result_array();
    }
}

控制器:

public function catpage(){
    $config['base_url'] = base_url() . "post/catpage";
    $config['total_rows'] = $this->post_model->record_count();
    $config['per_page'] = 2;
    $config['uri_segment'] = 3;

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    $data['posts'] = $this->post_model->get_category_posts(null, $config['per_page'], $page);
    $data['links'] = $this->pagination->create_links();

    $this->load->view('templates/header', $data);
    $this->load->view('posts/catpage', $data);
    $this->load->view('templates/footer');
}

查看:

<?php if(isset($posts) & ($posts <> NULL)){
    foreach($posts as $post_item): ?>
        <tr>
            <td><p><a href="<?php echo site_url('post/' . $post_item->slug);?>"><?php echo $post_item->post_title; ?></a></p></td>
            <td><p><?php echo $post_item->username; ?></p></td>
            <td><p><?php echo $post_item->post_date; ?></p></td>
            <td>Rating data</td>
            <td>View data</td>
        </tr>
    <?php 
    endforeach; 
}?>

此外,我还有一个处理个别slug的页面,因此我将NULL传递给方法,因为它当然要求3个参数。

谢谢。

0 个答案:

没有答案