Controller Response Types
Alloy controllers have a few useful response types that can be returned directly by the requested controller method. Note that since the response content is explicitly returned, if your controller method does not return anything, nothing will be displayed.
String Content
Returning raw strings is most useful for simple API responses that don't need their own templates. By returning a string directly, you can avoid the overhead of including and parsing another template or redundant formatting and markup code that might be unnecessary for simpler tasks.
View Objects
There is a convenience function on the controller named 'template' that returns an instance of \Alloy\View\Template and sets the local module path and response format for you automatically. Read Alloy Views for more details on specific methods and functionality.
Resource Objects
The Resource object is a flexible response type provided primarily for web service responses. It accepts an array of data or an object that has a toArray method, and will transform the data to a JSON response (XML coming soon). As an extension of the abstract module response, it also provides methods to set an HTTP status code, errors, and more.
Any object with a __toString method
Any object that can be converted to a string (ala __toString) will be properly rendered and handled by Alloy. This allows you to create and use your own (or other) code libraries for forms, view partials, whole template engines, or whatever else you need. Since nothing is already loaded for your controller, there is no waste of unused resources or code.
Boolean False
Boolean false is a special return type that will render a generic 404 "File Not Found" HTTP response that will match the one served by Alloy for modules or actions that do not exist. In the context of a nested sub-request, a boolean false controller response will not render any content, and the primary request (and other nested sub-requests) will continue as normal, un-interrupted.
Exceptions
Exceptions thrown anywhere within controller requests or nested sub-requests will stop execution and trigger an HTTP response unless caught in a try/catch block.
\Alloy\Exception\FileNotFound
Triggers a 404 "File Not Found" HTTP response with the exception message set as the response body.
\Alloy\Exception\Http
Generic and flexible way to trigger a desired HTTP response. Issues a HTTP response with the exception message set as the response body, and the exception code set as the HTTP response code.
\Alloy\Exception\Auth
Indicates the requested action requires authentication. Forces a user login and issues a 401 Unauthorized HTTP response.