Page 1 of 1

PUT vs. GET

Posted: Thu Apr 30, 2009 4:41 am
by The_Anomaly
The title says it all, really. I'm studying the Symfony framework, and I'm completely loving it--partly due to the excellence of their tutorial. Anyway, I keep getting stuck at the PUT HTTP method. See this page, near the end.

This code:

Code: Select all

 <?php echo link_to('Publish', 'job_publish', $job, array('method' => 'put')) ?>
Generates this link:

Code: Select all

<a href="/frontend_dev.php/job/c55fb50ef1d38aeb1c21b2361e6034b870eee5a5/publish" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', 'sf_method'); m.setAttribute('value', 'put'); f.appendChild(m);var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_csrf_token'); m.setAttribute('value', 'c14237ea8513e519b8d307661bed3a6d'); f.appendChild(m);f.submit();return false;">Publish</a>
Basically, why would one use PUT as opposed to GET in a certain case? And why would they even call it PUT when it seems that the form method set up by the javascript is actually POST.

Re: PUT vs. GET

Posted: Thu Apr 30, 2009 1:44 pm
by Christopher
The short answer is that PUT is not really a method that can be used with PHP, but it a REST concept that some find useful, so they implement it with a convention of a specifically named hidden POST form field.