PUT vs. GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

PUT vs. GET

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PUT vs. GET

Post 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.
(#10850)
Post Reply