我想在kohana中整合分页,但不知道发生了什么。我收到这些错误“Undefined variable:pager”

时间:2015-12-21 11:51:58

标签: php kohana-3 kohana-3.3

尝试在kohana 3.3中集成分页但是我在集成后得到这些错误“ErrorException [注意]:未定义变量:pager”以下是我的控制器:`

class Controller_Welcome extends Controller_Application
{

    public function action_index()
    {

        $content = View::factory('welcome')
        ->bind('messages', $messages);
        $message = new Model_Message;
        $message_count = $message->count_all();
        $pagination = Pagination::factory(array(
        'total_items' => $message_count,
        'items_per_page' => 3,
        ));
        $pager = $pagination->render();
        $messages = $message->get_all($pagination->items_per_page,$pagination->offset);
        $this->template->content = $content;
    }

} // End Welcome

视图是

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

1 个答案:

答案 0 :(得分:2)

您需要将$pager绑定到您的视图:

$content = View::factory('welcome')
    ->bind('messages', $messages)
    ->bind('pager', $pager);