From 1ee251445a7d722aa64c101c5d9b17628ac6ea01 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 21 Dec 2024 12:37:44 +0100 Subject: [PATCH] Document how to create a view without content --- README.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b5c7c60..1d8b383 100755 --- a/README.md +++ b/README.md @@ -114,7 +114,18 @@ class Hello { } ``` -The above method routes will only accept `GET` requests. `POST` request methods can be annotated with `Post`, `PUT` with `Put`, and so on. +The above method routes will only accept `GET` requests. `POST` request methods can be annotated with `Post`, `PUT` with `Put`, and so on. To overwrite the method used for POST requests, pass the special `_method` field: + +```html +
+ + +
+``` + +This will route the request as if it had been issued as `PUT /example HTTP/1.1`. + +### Views Route methods can return `web.frontend.View` instances to have more control over the response: @@ -127,6 +138,9 @@ return View::named('hello')->with(['greet' => 'World']); // Redirecting to either paths or absolute URIs return View::redirect('/hello/World'); +// No content +return View::empty()->status(204); + // Add headers and caching, here: for 7 days return View::named('blog') ->with($article) @@ -136,17 +150,6 @@ return View::named('blog') ; ``` -To overwrite the method used for POST requests, pass the special `_method` field: - -```html -
- - -
-``` - -This will route the request as if it had been issued as `PUT /example HTTP/1.1`. - ## Serving assets Assets are delivered by the `AssetsFrom` handler as seen above. It takes care of content types, handling conditional and range requests for partial content, as well as compression.