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

前端 未结 5 813
难免孤独
难免孤独 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:17

    If it was me I would run with your idea of saving the stuff into the session. Then I would add a page dimension to the session, to store each page, thus allowing users to go back and forth with ease.

    $this->Session->write('Search.page.1.params',$params);
    $this->Session->write('Search.page.2.params',$params2);
    

    In order to do it in a Cake way, you'd probably want to write your own Pagination helper, or plugin. Which you could then use more effectivly in your controllers as

    $this->MyPages->paginate('MyModel');
    

    I suppose, this functionality would also give you the option to allow your users to 'Save my search' if they wanted to, as you could dump the session params into a SavedSearch model or similar.

    Don't forget to $this->Session->destroy() before starting a new search though!

提交回复
热议问题