0
votes

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>

1
What happens? What errors do you get? - Barry Chapman
No errors, the table of Faq Articles do simply not paginate. - James J
try setting public $presetVars = array(); and do $this->Prg->commonProcess('SearchModel'); and see if that helps. - Barry Chapman
I've added $presetVars = array(); $this->Prg->commonProcess('FaqArticle'); To the controller function but no luck, nothing is paginated. Any other suggestions? - James J
Can you explain what you mean by, 'nothing is paginated'? Do you get ANY data at all? first page? - Barry Chapman

1 Answers

0
votes

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.