Overview
Leaf tries as much as possible to use raw PHP written from scratch, so, instead of using PSR-7 like most frameworks do, Leaf has written predefined response methods.
In v1.3, Request is now part of the HTTP namespace.
Including Response
To include the Response object in a route, use this:
$response
to the Response
class, and we pass it into the route with use()
.
Response Methods
In v1.3, Response methods no longer use theecho
keyword. Everything is handled in Response.
respond()
Respond is a method built for APIs and direct responses to the user. This response is encoded as JSON and output as such
respondWithCode()
RespondWithCode is also a method built for APIs and direct responses to the user. This response is encoded as JSON and output as such, but it includes a section for the http code(default is 200)
throwErr()
throwErr is also a method built for APIs and direct responses to the user, however, this method is suitable for errors only.
The response is encoded as JSON and output as such, also, the correct headers are set for the error. It also includes a section for the http error code.
More info on http status codes here
renderHtmlPage()
renderHtmlPage is a method built for websites and webapps. This method is can be used with the routing to achieve server side routing, for example:
/homepage
is invoked, Leaf loads up home.html
and outputs it to the user
renderMarkup()
renderMarkup is another method built for websites and webapps. This method outputs any html entered into it with a content type of text/html:
For instance, with this code,Hello
";hello
";renderMarkup
and renderHtmlPage
Next Steps
Simple RoutingRequest
Simple Authentication
Database Config