Reputation: 5
I use CakePHP 2.5.2. I have standard form, which I send by POST method.
I catch this post in controller and display data from database, but when someone refreshes the page, I can't read data again because parameters were provided by a POST request. So, I want to build URL like this:
http://example.com/controller/action/**firstDataFromPost**/**secondDataFromPost**
It makes my site refreshable, but I don't know how modify URL.
Upvotes: 0
Views: 74
Reputation: 24406
There are really two main options here:
Using the GET HTTP method instead of POST will mean your variables are automatically appended to the end of the querystring:
http://example.com/controller/action?firstDataFromPost&secondDataFromPost
You can post your form to an action that will assemble the variables required and redirect you to a page that doesn't have a dependent HTTP action anymore. Say you post to receive()
action:
public function receive() {
$var1 = $this->data['MyForm']['my_field1'];
$var2 = $this->data['MyForm']['my_field1'];
$this->redirect(array('action' => 'showresults', $var1, $var2));
}
Then your showresults()
action has passed parameters accessible at all times:
public function showresults($var1, $var2) {
// ... display your results here using these variables
}
... and your URL would look something like this:
http://example.com/controller/showresults/VAR1HERE/VAR2HERE
Upvotes: 2