The Controller 🎮
Up and Running 👟
Every route you specify in your application will end in the static method of a controller. Controller are PHP classes that are derived from the
Core/Controller base class.
The general naming format enforced by FMVC is
<name>Controller. This type of naming will be expected by the routing logic and serves to identify associated views and assets
that should be included automatically.
This will look something like this:
Now, after you got your fancy new controller, we need to populate it with some methods. These methods have to be public, static and need to get a reference on a
Core/Request class instance. Like this:
To easily handle common HTTP response types, the
Controller baseclass utilizes a module of quick actions that prepare the response and render the given input as string.
One of these methods can be seen in the above example rendering a view and returning it with the HTTP status Ok.
The parameter passed is an instance of the class PageView.
Ok there are also the following methods available:
All of the examples mentioned above can receive an implementation of the serializeable interface as parameter or nothing if there's nothing to render.
The return value of the controller method registered to handle the method will be printed onto the resulting document. Just as you are used from standard PHP applications. So if you want to do your own thing, feel free to just return a string. 😁