CakeDC搜索插件分页不起作用

时间:2012-10-10 11:23:20

标签: cakephp cakedc

您好我正在使用我的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>

1 个答案:

答案 0 :(得分:0)

此代码:

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

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

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