Resource
└─Hello
public class Hello
extends Resource
Fields inherited from Tonic\Resource | |
---|---|
params |
Method Summary | |
---|---|
str | sayHello(str name) Use this method to handle GET HTTP requests. |
str | sayHelloInFrench(str name) |
str | The @priority annotation makes this method take priority over the above method. |
str | |
protected void | only(mixed allowedName) Condition method for above methods. |
Response | The @provides annotation makes method only match requests that have a suitable accept header or URL extension (ie: /hello.json) and causes the response to automatically contain the correct content-type response header. |
protected void | json() Condition method to turn output into JSON |
Response | All HTTP methods are supported. |
Methods inherited from Tonic\Resource | |
---|---|
__construct, accepts, after, before, cache, exec, lang, method, priority, provides |
public str sayHello(str name)
Use this method to handle GET HTTP requests.
The optional :name parameter in the URL available as the first parameter to the method or as a property of the resource as $this->name.
Method can return a string response, an HTTP status code, an array of status code and response body, or a full Tonic\Response object.
public str sayHelloInFrench(str name)
public str replicants()
The @priority annotation makes this method take priority over the above method.
The custom @only annotation requires the matching class method to execute without throwing an exception allowing the addition of an arbitary condition to this method.
public str iveSeenThings()
protected void only(mixed allowedName)
Condition method for above methods.
Only allow specific :name parameter to access the method
public Response sayHelloComputer()
The @provides annotation makes method only match requests that have a suitable accept header or URL extension (ie: /hello.json) and causes the response to automatically contain the correct content-type response header.
protected void json()
Condition method to turn output into JSON
public Response feedTheComputer()
All HTTP methods are supported. The @accepts annotation makes method only match if the request body content-type matches.
curl -i -H "Content-Type: application/json" -X POST -d '{"hello": "computer"}' http://localhost/www/tonic/web/hello.json
The obligitory Hello World example
The @uri annotation routes requests that match that URL to this resource. Multiple annotations allow this resource to match multiple URLs.