The controller handles the main flow of the application and is responsible for returning a response to the client.
When a request is routed to a controller class, an instance of this controller is created and a suitable action method is invoked automatically.
To create a controller class, extend the BlueMvc\Core\Controller base class:
use BlueMvc\Core\Controller; class MyController extends Controller
To handle a request, one or more action methods must be implemented in the controller.
Methods with public visibility, having a name that ends with Action are considered to be action methods.
There are three types of action methods:
public function indexAction()
The index action handles request for the index page, e.g. / or /foo/.
public function barAction()
A custom action method will, in it's basic form, handle requests for the page corresponding to the name preceding Action, e.g. /bar or /foo/bar.
public function defaultAction($action)
The default action handles requests where no other suitable action method was found.
The $action parameter is required and will contain a string with the action name.
The controller contains some methods that can be useful when processing the request.
Returns the current application instance.
Returns the current request from the client.
Returns the response that will be sent to the client.
The controller contains two methods that can be overridden to run code before and after an action method is invoked.
protected function onPreActionEvent()
This method is invoked before the action method.
protected function onPostActionEvent()
This method is invoked after the action method.
✎ Published in category core