【发布时间】:2011-09-20 16:06:55
【问题描述】:
我有问题。我的 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;
}
}
【问题讨论】:
-
删除您的问题对花时间回答问题的人不公平。
标签: php frameworks kohana