我有问题。我的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;
}
}
答案 0 :(得分:1)
有两个问题:
分页对象仅用于呈现分页控件,不执行db记录的实际过滤。
答案 1 :(得分:1)
你可以设置bootstrap.php:
Route::set('index_page','yourcontroller/index(/<page>)', array('page' => '[0-9]+'))
->defaults(array(
'controller' => 'yourcontroller',
'action' => 'index',
));