cakePHP paginate with post data without sessions, serialization or post to get

前端 未结 5 811
难免孤独
难免孤独 2021-01-12 21:49

I have created a small search and filter form with a POST action in controller/index, which POSTs to itself the conditions and fields to paginate ($this->paginate($

5条回答
  •  离开以前
    2021-01-12 22:12

    Thanks Deizel for the POST / REDIRECT / GET pattern.

    I implemented the GET method of posting data. For pagination used this
    $urlparams = $this->params['url'];unset($urlparams['url']); $paginator->options(array('url' => array('?' => http_build_query($urlparams))));

    We had multi checkboxes and the naming convention used where :
    foreach ($checkboxes as $chbox ) {

    // used variable variables to generate the data grid table based on selected fields
    ${'_field'.$chbox} = (isset($this->params['url']['displayfields'][$chbox])?$this->params['url']['displayfields'][$chbox]:1);
    
    $options = array('label'=>$chbox,'type'=>'checkbox','value'=> ${'_field'.$chbox});
    if ( ${'_field'.$chbox} ) $options['checked'] = 'checked';
    
    echo $form->input('Filter.displayfields['.$chbox.']',$options);
    



    In the post method the naming convention for the checkboxs would be Filter.displayfields.checkbox name

    This helps in getting an array either in $this->data or $this->params['url']

    There should be an persistent pagination plugin/component for cakePHP would make life much more easier and fun to develop with cakePHP.


    Thanks all.

提交回复
热议问题