I have to rewrite a form in a CakePHP application. The form searches a list of car sale ads and is pretty complex (~10 fields: model, manufacturer, fuel type etc.). Currently, the form is sent via POST and is working quite well. The problem is I need to create bookmarkable URLs from the search queries and I was wondering what was the best way to accomplish this.
I tried passing 'type' => 'get' to the $form->create() method, but this generates a URL like usercars/search/?model=...&[...] and causes the search to break.
I want the URL to be something like <some routing>/<Manufacturer>/<Model>/<Fuel>/<etc>, and also to support parameter omission (i.e. <some routing>/<Manufacturer> to list all the cars from the given manufacturer, even if the other parameters are missing). By POST, currently this works. If I select only one of the params, it gives me the correct results.
I wonder if there's any way to determine cake to build the nice url from the form submission and maintain compatibility with the $this->data way of handling input in the controller. I've gone through the documentation and haven't found any way to do this.
I already have two alternatives:
- rewriting the controller action to support function parameters instead of working with
$this->data, building a route that targets the search method with the params and doing a redirect in the controller'sbeforeFilter()method to a URL that corresponds to the route. - doing javascript on the search form page to build the URL + the above way of handling it.
What would you recommend?