CI 分页问题
我是CI新手,在使用它的分页类的时候,出现了一些问题,和手册上的代码一样的,去不出现效果!这是我在控制器中的代码
class Home extends Controller
{
function __construct()
{
parent::Controller();
$this->load->library('pagination');
$this->load->model('article');
}
function index()
{
$config['total_rows']=$this->article->get_all_rows();
$config['pre_page']='10';
$config['base_url']=base_url().'home/index/';
$this->pagination->initialize();
$data['list']=$this->article->get_page($this->uri->segment(3,0),$config['pre_page']);
$this->load->view('index',$data);
}
}
这是在视图中的代码:
<html>
<head>
<title>分页</title>
</head>
<body>
<?foreach ($list as $row):?>
<p><?=$row->tg_title?></p>
<?endforeach;?>
<div><?php echo $this->pagination->create_links()?></div>
</body>
</html>
这是模型的代码
class Article extends Model {
function __construct()
{
parent::Model();
}
function get_all_rows()
{
$query=$this->db->query("select * from tg_article");
return $query->num_rows();
}
function get_page($off,$pagesize)
{
$query=$this->db->query("select * from tg_article limit $off,$pagesize");
return $query->result();
}
}
程序没有报错,但是按理说在视图中应该会出现这样的效果,<<first1 2 3 4 5 last>>
但是在我的视图中查看时,什么也没有,程序也没有报错,在URI段中输入相相应的页码时,也可以显示相应页的内容,但是就是没有显示像<<first1 2 3 4 5 last>>这样的字符,
请高手指教一下!小弟感激不尽啊! 是$config['per_page']
不是$config['pre_page'] function index()中你输出 $this->article->get_all_rows(); 看是不是大于10 $config['total_rows'] 大于 $config['pre_page']才会显示分页 pxc2471418 发表于 2011-10-18 17:05 static/image/common/back.gif
function index()中你输出 $this->article->get_all_rows(); 看是不是大于10
不是啊,我的总条数只有三条,设的每分显示两个条,按理应该出来两页啊,可是现在就是不出来<<frist12 last>> 等这样的页码字符!但是我在地址栏中直接传页码时,又会显示对应页的内容! pxc2471418 发表于 2011-10-18 17:07 static/image/common/back.gif
$config['total_rows'] 大于 $config['pre_page']才会显示分页
我的$config['total_rows']是大于$config['pre_page']的啊 啊,有人悬赏。
可惜我没赶上。 用的CI是什么版本啊? ~夜行侠~ 发表于 2011-10-19 14:48 static/image/common/back.gif
用的CI是什么版本啊?
版本有问题吗?2.0.3 visvoy 发表于 2011-10-18 21:47 static/image/common/back.gif
是$config['per_page']
不是$config['pre_page']
晕,这种错误也犯!
页:
[1]
2