0

Hi I'm currently using the CakeDC search plugin for my CakePHP (2.2 app).

The search facility itself works fine, however I cannot get the results or the data shown on page before the search to paginate.

Heres my code

Model:

   // Configure Meio file uploader
var $actsAs = array(
    'MeioUpload.MeioUpload' => array(
        'filename' => array(
            'allowedMime' => array('image/jpeg', 'image/pjpeg', 'image/png', 'application/pdf'),
            'allowedExt' => array('.jpg', '.jpeg', '.png', '.pdf'),
            'maxSize' => '8 Mb'
        )
    ),
    'Search.Searchable'
);

// Search plugin filters
public $filterArgs = array(
    'title' => array('type' => 'like'),
    'live' => array('type' => 'value'),
    'search' => array('type' => 'like', 'field' => 'FaqArticle.description'),
    'error' => array('type' => 'like'),
    'description' => array('type' => 'like')
);

Controller:

// Search plugin
public $components = array('Search.Prg');
public $presetVars = true; // using the model configuration

public function admin_index() {

$this->Prg->commonProcess();
    $this->paginate = array('conditions' => $this->FaqArticle->parseCriteria($this->passedArgs));
    $this->set('faqArticles', $this->paginate());

    // Count all live articles for intro text
    $this->set('liveArticles', $this->FaqArticle->find('count', array('conditions' => array('FaqArticle.live' => '1')
    )));

    // Count all articles for intro text
    $this->set('countedArticles', $this->FaqArticle->find('count'));

    // Set searched for details
    $this->set('searchedFor', $this->passedArgs);

    // Set layout
    $this->layout = 'admin';
}

View:

<div class="pagination">
    <ul>
    <?php
        echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'modulus' => '5'));
        echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
    ?>
    </ul>

Jimothey
  • 2,414
  • 9
  • 41
  • 66

1 Answers1

0

this code:

public $components = array('Search.Prg');
public $presetVars = true; // using the model configuration

Should be in your controller, not your model. Models don't have 'components'. Controllers have 'components'. And check the doco for the Serach plugin - the $filterArgs goes in the model (which you've done correctly), but the $presetVars goes in the controller.

Don't set $presetVars as an empty array. Just move it from your model to your controller. It should be declared up the top as a public var, as you've done in your model, and shouldn't be declared inside the admin_index method.

joshua.paling
  • 13,762
  • 4
  • 45
  • 60
  • Hi, thanks for the reply. I've updated my code to reflect your changes but nothing has changed. (Updated the code above to reflect the changes) any other ideas? Its neither paginated on page load or on a search. – Jimothey Oct 11 '12 at 08:51
  • Not really, sorry. I just got it working with pagination in Cake 2.2, so I don't think the plugin itself is broken. I'd be making the simplest case possible, and then looking at the SQL log. Comment out MeioUpload behaviour. Comment out liveArticles, countedArticles, etc. from your controller and view. Then try to get search working for just one field only - title. Look at the SQL generated, etc. Do a print_r($this->paginate); after you call $this->paginate = array('conditions' => $this->FaqArticle->parseCriteria($this->passedArgs)); Get a simplest case working, then add stuff back in. – joshua.paling Oct 11 '12 at 22:05