2

我有这个观点

 ?php echo $this->Form->create('Search', array('id' => 'Search', 'url' => array('controller' => 'mycontroller', 'action' => 'index'))); ?>
<?php echo $this->Form->input('usuario_id', array('label' => __('Vendedores', true), 'options' => $vendedores, 'empty' => true)); ?>
<?php echo $this->Form->input('cliente_id', array('label' => __('Cliente', true), 'options' => $clientes, 'empty' => true)); ?>
<?php echo $this->Location->estados(); ?>
<?php echo $this->Location->municipios(); ?>
<?php echo $this->Location->bairros(); ?>
<?php echo $this->Form->input('equipe_id', array('label' => __('Equipe', true), 'options' => $equipe, 'empty' => true)); ?>
<?php echo $this->Form->input('veiculo_id', array('label' => __('Modelo', true), 'options' => $veiculos, 'empty' => true)); ?>
<?php echo $this->Form->input('status', array('label' => __('Status', true), 'options' => $status, 'empty' => true,'multiple' => true )); ?>
<?php echo $this->Utils->data('date_from', array('input' => array('label' => 'De'))); ?>
<?php echo $this->Utils->data('date_to', array('input' => array('label' => 'a'))); ?>
<?php echo $this->Form->hidden('Search.search'); ?>
<?php echo $this->Form->end('Buscar'); ?>

和我的控制器分页条件是这样的

if(!empty($this->data['Search']['myvar_id'];)) $this->paginate['conditions']['myModel.myvar_id'] = $this->data['Search']['myvar_id'];

所有搜索字段都工作正常,在#1 页面中,没关系,但是当我分页到#2 页面时,值被清除。如您所见,我在表单上使用了 post 方法,所以使用这种情况,我如何确定当我分页时值不会丢失?

先谢谢了!

4

1 回答 1

-1

这是您可以做的一件简单的事情

if(isset($this->data[<some variable>])){
            if(!empty($this->data[<some variable>])){
                $keyword = trim($this->data[<some variable>]);
                $this->redirect('/controller/action/keyword:'.$keyword.));

    }
        }elseif(isset($this->params['named']['keyword'])){
            if(!empty($this->params['named']['keyword'])){
                $keyword =$this->params['named']['keyword'];
                 $this->paginate['conditions'] = array("ModelName.Fieldname LIKE" => "%$keyword%");
            }
        }

这是一种最好最简单的方法 4 维护分页值,您可以在参数中拥有多个关键字,并且可以在条件后缀中使用。

于 2012-06-18T10:02:30.713 回答