我有一个像我这样过滤我的分页器的函数:
public function indextipo() {
$this->CabAsiento->recursive = 0;
$tipo = $this->request->data['tipo'];
$fecha = $this->request->data['fecha_desde'];
$this->Paginator->settings=array(
'paramType' => 'querystring',
'limit'=> 1,
'conditions' => array('CabAsiento.tipo_doc' => $tipo, 'MONTH(CabAsiento.fecha)' => $fecha),
'order' => array('CabAsiento.id_numero' => 'ASC')
);
$this->set('cabAsientos', $this->Paginator->paginate());
$this->layout = 'ingresos';
}
它有.ctp。
它可以工作并显示过滤器数据,但是当我尝试下一页时,其他页面会给我:
未定义的索引:tipo [APP \ Controller \ CabAsientosController.php,第35行]
未定义索引:fecha_desde [APP \ Controller \ CabAsientosController.php,第36行]
导致参数丢失。 如何保存或存储通过表单搜索发送的参数:
<div class="portlet-body">
<?php echo $this->Form->create(false, array('action' => 'indextipo','id' => 'form-login1')); ?>
<fieldset>
<?php
echo $this->Form->input('fecha_desde', array('id'=>'fecha_desde1', 'type' => 'date','dateFormat' => 'M','class' => 'span3'));
$arrCategory=array("ing"=>"Ingreso","egre"=>"Egreso","trasp"=>"Trapaso");
echo $this->form->input('tipo',array('type' => 'select','options'=> $arrCategory));
?>
</fieldset>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<?php
echo $this->Form->button("<i class='icon-plus'></i> Buscar", array('type' => 'submit','id' => 'submit_id', 'class' => 'btn green', 'escape' => false, 'aria-hidden'=>"true"));
echo $this->Form->end();
?>
</div>
答案 0 :(得分:0)
我认为您所寻找的内容可以使用Search Plugin进行设置。
您的控制器应如下所示:
class ArticlesController extends AppController {
public $components = array(
'Search.Prg'
);
public function find() {
$this->Prg->commonProcess();
$this->Paginator->settings['conditions'] = $this->Article->parseCriteria($this->Prg->parsedParams());
$this->set('articles', $this->Paginator->paginate());
}
}
答案 1 :(得分:0)
在访问这些数据之前,您必须检查它们的存在。
public function indextipo() {
$settings = array(
'paramType' => 'querystring',
'limit' => 1,
'order' => array('CabAsiento.id_numero' => 'ASC')
);
//Check if data are submited
if ($this->request->is('post')) {
$tipo = $this->request->data('tipo');
$fecha = $this->request->data('fecha_desde');
$settings['conditions'] = array('CabAsiento.tipo_doc' => $tipo, 'MONTH(CabAsiento.fecha)' => $fecha);
}
$this->CabAsiento->recursive = 0;
$this->Paginator->settings = $settings;
$this->set('cabAsientos', $this->Paginator->paginate());
$this->layout = 'ingresos';
}
答案 2 :(得分:0)
好了几个信息之后做了:
if(isset($this->request->data['tipo']) && isset($this->request->data['fecha_desde']) && isset($this->request->data['numero']))
{
$this->Session->write('tipo', $this->request->data['tipo']);
$this->Session->write('fech', $this->request->data['fecha_desde']);
$this->Session->write('num', $this->request->data['numero']);
}
$tipo = $this->Session->read('tipo');
$fecha = $this->Session->read('fech');
所以我正在使用会话数据来保存我的搜索参数,如果我要更改页面或其他类型的搜索,这些数据将会保留。