Class Controller
A route controller.
Accessing the application's properties
The class tries to retrieve undefined properties from the application, so the following code
yields the same results:
<?php
$this->app->models
$this->models
But because request
is defined by the controller the following code might not yield the same
results:
<?php
$this->app->request
$this->request
-
ICanBoogie\Object
-
┗
ICanBoogie\Routing\Controller
Methods summary
protected
get_name( void )
: string|null
Return the name of the controller, extracted from its class name.
Return the name of the controller, extracted from its class name.
Returns
string|null
The underscored name of the controller, or null
if it cannot be
extracted.
protected
get_request( void )
protected
lazy_get_response( void )
: ICanBoogie\HTTP\Response
Returns
ICanBoogie\HTTP\Response
final public
__invoke( ICanBoogie\HTTP\Request $request
)
: ICanBoogie\HTTP\Response|mixed
Controls the route and returns a response.
Controls the route and returns a response.
The response is obtained by invoking action()
. When the result is a ICanBoogie\HTTP\Response
instance it is returned as is, when the $response
property has been initialized the result
is used as its body and the response is returned, otherwise the result is returned as is.
The ICanBoogie\Routing\Controller::action:before
event of class
ICanBoogie\Routing\Controller\BeforeActionEvent
is fired before invoking action()
, the
ICanBoogie\Routing\Controller::action:before
event of class
ICanBoogie\Routing\Controller\ActionEvent
is fired after.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
abstract protected
action( ICanBoogie\HTTP\Request $request
)
: ICanBoogie\HTTP\Response|mixed
Performs the proper action for the request.
Performs the proper action for the request.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
protected
last_chance_get( string $property
, boolean & $success
)
: mixed
Tries to get the undefined property from the application.
Tries to get the undefined property from the application.
Parameters
Returns
mixed
public
redirect( ICanBoogie\Routing\Route
|string $url
, integer $status
= 302, array $headers
= [] )
: ICanBoogie\HTTP\RedirectResponse
Redirects the request.
Parameters
$url
- The URL to redirect the request to.
$status
- Status code (defaults to 302).
$headers
- Additional headers.
Returns
ICanBoogie\HTTP\RedirectResponse
protected
forward_to_route( ICanBoogie\Routing\Route
$route
)
: ICanBoogie\HTTP\Response|mixed
Forwards dispatching to another router.
Forwards dispatching to another router.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
Properties summary
Magic properties
public
$response
: ICanBoogie\HTTP\Response
public read-only
$name
: string
The name of the controller.
public read-only
$request
: ICanBoogie\HTTP\Request
The request being dispatched.
public read-only
$app
: ICanBoogie\Core
public read-only
$module
: ICanBoogie\Module
The module defining the route. (This getter is provided by the icanboogie/module package)
public read-only
$model
: ICanBoogie\ActiveRecord\Model
The primary model of the module. (This getter is provided by the icanboogie/module package)
public read-only
$events
: ICanBoogie\Events
Provided through prototype getters or through $app
.