0

您好我目前正在为我的 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>

4

1 回答 1

0

这段代码:

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

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

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

于 2012-10-10T22:35:39.837 回答