编辑
我已经添加了我的 /application
目录的 github 存储库。
https://github.com/ashleyconnor/Egotist
我正在阅读 Packt Publishing 的“Kohana 3:初学者指南”,并且刚刚完成了第 7 章。
我遇到的问题是在我的主页上,我从消息模型呈现分页 url,但第二个 url 指向不存在的路由。
我已经突出显示 View 在正确 URL 之前呈现 1
的位置。
我遇到的另一个问题是在整个屏幕上随机打印 1
。这是因为我在开发模式下编码吗?
Controller :
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller_Application {
public function action_index()
{
$content = View::factory('welcome')
->bind('messages', $messages)
->bind('pager_links', $pager_links);
$message = new Model_Message;
$message_count = $message->count_all();
$pagination = Pagination::factory(array(
'total_items' => $message_count,
'items_per_page' => 3,
));
$pager_links = $pagination->render();
$messages = $message->get_all($pagination->items_per_page, $pagination->offset);
$this->template->content = $content;
}
}
查看:
<h1>Recent Messages on Egotist</h1>
<?php foreach ($messages as $message) : ?>
<p class="message">
<?php echo $message->content; ?>
<br />
<span class="published">
<?php echo Date::fuzzy_span($message->date_published); ?>
</span>
</p>
<hr />
<?php endforeach; ?>
<?php echo $pager_links; ?>
输出片段:
<p class="pagination">
First
Previous
<strong>1</strong>
<a href="1/?page=2">2</a> <--misbehaving
<a href="/?page=3">3</a>
<a href="/?page=4">4</a>
<a href="/?page=5">5</a>
<a href="/?page=6">6</a>
<a href="/?page=7">7</a>
<a href="/?page=8">8</a>
<a href="/?page=2" rel="next">Next</a>
<a href="/?page=8" rel="last">Last</a>
</p><!-- .pagination -->
最佳答案
在您的 Controller_User_Account
和 HTML
类中:
替换
<?php echo defined('SYSPATH') or die('No direct access allowed.');
与
<?php defined('SYSPATH') or die('No direct access allowed.');
关于php - Kohana 3 分页渲染不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7536135/