用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2479|回复: 2
收起左侧

[HELP] 照着论坛的分页写有点问题问题

[复制链接]
发表于 2010-8-5 14:59:21 | 显示全部楼层 |阅读模式
控制器books.php

<?php
        class Books extends Controller
        {
                function  Books()
                {
                        parent::Controller();
                        $this->load->helper('url');
                        $this->load->database();
                }
                function index()
                {
                        $this->load->library('pagination');
                        $config['total_rows']=$this->db->count_all('ci1');
                        $config['per_page']=2;
                        $config['uri_segment']=3;
                        $config['full_tag_open']='<p>';
                        $config['full_tag_close']='</p>';
                        $this->pagination->initialize($config);
                        $this->load->model('books_model');
                        $data['results']=$this->books_model->get_books($config['per_page'],$this->uri->segment(3));
                        $this->load->library('table');
                        $this->table->set_heading('ID','Title','Author','Description');
                        $this->load->view('books_view',$data);
                }
        }
?>

模型层
books_model.php

<?php
        class books_model extends Model
        {
                function  books_model()
                {
                        parent::Model();
                }
                function get_books($num,$offset)
                {
                        $query=$this->db->get('ci1',$num,$offset);
                        return $query;
                }
        }
?>

视图
books_view.php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>CI  分页</title>
</head>
<h1>分页</h1>
<?php echo $this->table->generate($results); ?>
<?php echo $this->pagination->create_links(); ?>
</html>

运行结果。。

1.jpg

2.png
 楼主| 发表于 2010-8-5 15:00:07 | 显示全部楼层
第2页的链接怎么这样啊???
发表于 2010-8-5 15:52:22 | 显示全部楼层
你没设置分页类的 base_url
参考教程:http://codeigniter.org.cn/forums/thread-17-1-1.html

本版积分规则