Search code examples
phpkohana-3kohana-3.3

I am trying to integrate pagination in kohana, but don't know what is happening. I get these error " Undefined variable: pager"


trying to integrate pagination in kohana 3.3 but i get these error after integration "ErrorException [ Notice ]: Undefined variable: pager" Following is my controller: `

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

And the view is

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

Solution

  • You need to bind $pager to your view:

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