Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination with ORM / search function
  • Hi guys,

    I have to admit I'm a bit lost with the pagination module. I rarely use it and if I happen to need it I just paste a snippet.

    Now I had to add it to a page with a large number of records - so far so good. But I just noticed that the search function I've implemented throws an exception when used with enabled pagination.

    [ Fatal Error ]:
    Call to a member function pages_render() on a non-object
    APPPATH/views/contacts/index.php @ line 59

    Line 59:
    <ul class="pagination pagination-sm pull-right"> <?php echo Pagination::instance('pagination')->pages_render(); ?> </ul>

    I think it has to do with the search function I'm using.

    I'm using this for the working index page
    $data['contacts'] = Model_Contact::query()->rows_offset($pagination->offset)->rows_limit($pagination->per_page)->order_by($order)->get();

    While I pass search to a separate function
    $data['contacts'] = Model_Contact::search(Input::post('search'), $fuzzy);

    Snippet from model_contact::search
     <?php   public static function search($pattern, $fuzzy=false)
            if(Auth::member(100)) {
                if($fuzzy) {
                    $result = Model_Contact::find('all', array(
                    'where' => array(array('email', 'LIKE', "%$pattern%"), 'or' => array(array('name', 'LIKE', "%$pattern%"),),'or' => array(
                    array('forename', 'LIKE', "%$pattern%"),),),))->rows_offset(\Pagination::get('offset'))->rows_limit(\Pagination::get('per_page'))->get();
                } else {
                    $result = Model_Contact::find('all', array(
                    'where' => array(array('email', 'LIKE', "%$pattern%"), 'or' => array(array('name', 'LIKE', "%$pattern%"),),),));

    How should I handle pagination with the search ?
  • I assume you get the exception because your view attempts to load a named instance:


    but that instance was never created (in which case instance() will return false).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion