搜索无法在页面:2上使用cakeDC搜索插件

问题描述 投票:0回答:2

我目前有一个功能良好的搜索工具,使用 cakeDC 搜索插件。我可以通过分页很好地搜索。

我的问题是,当我从 page:2 搜索时,它根本不存在。

这是我的代码:

客户模型

public $actsAs = array('Search.Searchable');
public $filterArgs = array(
    'searchTerm' => array(
        'type' => 'like',
        'field' => array('Customer.name', 'Customer.mobile', 'Customer.address'),
        'filter' => array('type' => 'query', 'method' => 'orConditions')
    )
);

public function orConditions($data = array()) {
    $filter = $data['filter'];
    $cond = array(
        'OR' => array(
            'Customer.name LIKE' => '%' . $filter . '%',
            'Customer.mobile LIKE' => '%' . $filter . '%',
            'Customer.address LIKE' => '%' . $filter . '%',
    ));
    return $cond;
}

客户控制器

 public $components = array('Paginator', 'Session', 'Search.Prg');

 public $presetVars = true;

 public function index() {
    $this->Prg->commonProcess();
    $this->paginate = array();
    $conditions = $this->Customer->parseCriteria($this->passedArgs);
    $this->Customer->recursive = 0;
    $this->paginate = array(
        'limit' => 5,
    );
    $this->set('customers', $this->paginate($this->modelClass, $conditions));
    $this->set('model', $this->modelClass);
}

index.ctp

<?php echo $this->Form->create() ?>
<?php echo $this->Form->input('searchTerm', array('class' => 'form-control','placeholder' => 'search for customer', 'label' => FALSE,'url' => array_merge(array('action' => 'index'), $this->params['pass']))); ?>
<?php echo $this->Form->end() ?>

错误:在此服务器上找不到请求的地址“/KPautos/products/index/page:2?searchTerm=j”。

搜索无法在第 2 页上运行...

如有任何帮助,我们将不胜感激...提前谢谢您

php cakephp cakephp-2.3 cakedc
2个回答
1
投票

尝试编写此代码来创建表单

<?php echo $this->Form->create(null, array('type'=>'get','url' => array('page'=>'1')));?>

而不是

<?php echo $this->Form->create() ?>

0
投票

当我使用 CakePHP 2.6 的 CakeDC 插件从分页中的任何页面搜索时,我也遇到同样的问题,我知道 page:2 或 page:3 不存在,所以这就是搜索时标记为“未找到”的原因,所以感谢Sadikhasan 我将创建形式更改为:

echo $this->Form->create(null, array('novalidate' => true,'type'=>'get','url' => array('action'=>'index')));

索引是我用于搜索的主要页面..

© www.soinside.com 2019 - 2024. All rights reserved.