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

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

    You can also use the Post/Redirect/Get design pattern pattern to solve this, allowing users to bookmark URLs of searches (without them expiring as a session would) and keeping URLs looking friendly. For example:

    function index($searchTerms = null) {
        // post/redirect/get
        if (isset($this->data['SearchForm'])) {
            $this->redirect(array($this->data['SearchForm']['search_terms']));
        }
        // your normal code here.
    }
    

    The search form data POSTs to /controller/action but the user is redirected and instead GETs /controller/action/search+terms where the terms are passed into the action as a parameter (ie. $searchTerms).

    If you simply change the form submission method to GET you will instead see something like: /controller/action?data[SearchForm][search_terms]=search+terms

提交回复
热议问题