php - Kohana 3 分页渲染不正确

标签 php pagination routes kohana-3

编辑

我已经添加了我的 /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_AccountHTML 类中:

替换

<?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/

相关文章:

php - 如何使用 tcpdf 缩放图像?

php - 如何在不更改域名的情况下开发手机版网站?

web-services - 使用分页过滤远程结果

ruby-on-rails - 在 rspec 测试中调用 Rails.application.routes.recognize_path 与 Rails 3 中的任何路由都不匹配

javascript - AngularJS 的路由问题

c# - 是否可以将 URL 解析为它的复合组件?

php - 如何将位置 header 添加到来自 Codeigniter Rest 服务器的 http 响应

php - 如何通过 PHP 访问 JSON 数组数组中的字符串对象?

php - 如何计算分页的偏移量?

c# - 尝试从分页网址中获取所有项目时结果不一致