The POST parameter is retrieved with $request->request->get. $name = $request->request->get('name', 'guest') We change the controller to process the POST request. $message = $request->request->get('message', 'hello there') Src/Controller/HomeController.php request->get('name', 'guest') In the following example, we process a POST request in a Symfony application. Advertisements PHP POST request in Symfony $ curl 'localhost:8000/?name=Lucia&message=Cau' The second parameter of the method is a default value which is used when no The GET parameter is retrieved with $request->query->get. $name = $request->query->get('name', 'guest') We get the query parameters and create a response. Inside the HomeController's index method, Return new Response($output, Response::HTTP_OK, $message = $request->query->get('message', 'hello there') Src/Controller/HomeController.php query->get('name', 'guest') In the following example, we generate a GET request with curl tool and process Multipart/form-data as the HTTP Content-Type in the request. POST method when using application/x-www-form-urlencoded or Is an associative array of variables passed to the current script via the HTTP The $_GET is an associative array of variables passed to theĬurrent script via the URL parameters (query string). PHP provides the $_GET and $_POST superglobals.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |