【问题标题】:CakePHP store parameters to the paginator settingsCakePHP 将参数存储到分页器设置中
【发布时间】:2016-04-19 22:21:45
【问题描述】:

我有一个功能可以像这样过滤我的分页器:

    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>

【问题讨论】:

    标签: jquery cakephp cakephp-2.0 cakephp-2.3 cakephp-2.1


    【解决方案1】:

    我认为您可以使用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());
        }
    }
    

    【讨论】:

      【解决方案2】:

      在访问这些数据之前,您必须检查它们的存在。

      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';
      }
      

      【讨论】:

        【解决方案3】:

        经过几条信息后确定了:

        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');  
        

        所以我使用会话数据来存储我的搜索参数,如果我要更改页面或其他类型的搜索,这些数据将被保留。

        【讨论】:

          猜你喜欢
          • 2012-02-29
          • 1970-01-01
          • 1970-01-01
          • 2014-03-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-02
          • 1970-01-01
          相关资源
          最近更新 更多