蛋糕DC搜索插件分页不起作用



嗨,我目前正在为我的CakePHP(2.2应用程序)使用CakeDC搜索插件。

搜索

工具本身工作正常,但是在搜索分页之前,我无法获得页面上显示的结果或数据。

这是我的代码

型:

   // 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')
);

控制器:

// 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';
}

视图:

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

以下代码:

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

应该在你的控制器中,而不是你的模型中。模型没有"组件"。控制器具有"组件"。并检查 Serach 插件的 doco - $filterArgs进入模型(您已完成正确),但$presetVars进入控制器。

不要将$presetVars设置为空数组。只需将其从模型移动到控制器即可。它应该像在模型中所做的那样,在顶部声明为公共变量,并且不应该在 admin_index 方法中声明。

最新更新