为什么分页不能正常工作?
我有一个问题。我的 Kohana 分页脚本无法正常工作。必须如下:[http://127.0.0.1/?page=1],但我有以下 - [http://127.0.0.1/index.php/?page=1] 和来自主页数据库的记录页数为 2(总记录数为 2,我将 items_per_page 设置为 1),但必须只有 1 条记录。问题出在哪里?
控制器:
public function action_index()
{
$pagination = Pagination::factory(array(
'total_items'=> Model::factory('index')->get_count(),
'items_per_page' => 1,));
$articles_ = Model::factory('index')->do_magic();
$this->template->page_title = 'Sākums';
$this->template->site_name = Kohana::$config->load('common')->get('site_name');
$this->template->content = View::factory('index/index')
->set('query', $articles_)
->set('pagjinaacija', $pagination->render());
$this->template->styles[] = 'index/index';
}
视图
<?php
foreach($query as $row) {
echo '<h2>'.$row['title'].'</h2>';
echo '<p style="margin:0">'.$row['content'].'</p>';
}
echo $pagjinaacija;
?>
和模型
Class Model_Index Extends Model {
public function get_count() {
return DB::query(Database::SELECT, 'SELECT COUNT(*) AS count FROM posts')->execute()->get('count');
}
public function do_magic() {
$query = DB::query(Database::SELECT, 'SELECT * FROM posts ORDER By id DESC')->execute()->as_array();
return $query;
}
}
I have a problem. My Kohana pagination script not working correctly. Must have as follows : [http://127.0.0.1/?page=1], but I have the following - [http://127.0.0.1/index.php/?page=1] and records from database in home page are 2 (total records is 2, i set items_per_page to 1), but must have a 1 record only. Where is the problem?
Controller:
public function action_index()
{
$pagination = Pagination::factory(array(
'total_items'=> Model::factory('index')->get_count(),
'items_per_page' => 1,));
$articles_ = Model::factory('index')->do_magic();
$this->template->page_title = 'Sākums';
$this->template->site_name = Kohana::$config->load('common')->get('site_name');
$this->template->content = View::factory('index/index')
->set('query', $articles_)
->set('pagjinaacija', $pagination->render());
$this->template->styles[] = 'index/index';
}
View
<?php
foreach($query as $row) {
echo '<h2>'.$row['title'].'</h2>';
echo '<p style="margin:0">'.$row['content'].'</p>';
}
echo $pagjinaacija;
?>
And model
Class Model_Index Extends Model {
public function get_count() {
return DB::query(Database::SELECT, 'SELECT COUNT(*) AS count FROM posts')->execute()->get('count');
}
public function do_magic() {
$query = DB::query(Database::SELECT, 'SELECT * FROM posts ORDER By id DESC')->execute()->as_array();
return $query;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有 2 个问题:
分页对象仅用于呈现分页控件,不执行数据库记录的实际过滤。
There are 2 problems:
The pagination object is only used to render a pagination control, not perform the actual filtering of db records.
你可以设置 bootstrap.php:
you maybe set bootstrap.php: