Controller
Controller
Properties
name
protected string $name
request
protected Request $request
statusCode
protected int $statusCode
basePath
protected string $basePath
_helpers
private array $_helpers
cachedActions
private array $cachedActions
cachedResponses
private array $cachedResponses
responseCache
public Cache $responseCache
redirectCookieName
private string $redirectCookieName
Methods
__construct
Base controller constructor.
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$name | string | The name of the controller. This is the name used when generating URLs. |
__toString
Convert the controller object into a string.
public __toString({Array})
__get
Get the specified helper object.
public __get({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | the name of the helper |
initialize
Controller initialisation method.
public initialize({Array})
This should be called by all extending controllers and is simply responsible for storing the calling request.
Parameters
Parameter | Type | Description |
---|---|---|
$request | Request | the application request object |
run
public run({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$route | Route |
runAction
public runAction({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$actionName | string | |
$actionArgs | array |
shutdown
public shutdown({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$response | Response |
getName
Get the name of the controller.
public getName({Array})
setStatus
Set the default return status code.
public setStatus({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$code | int |
getStatus
Get the status code of the controller.
public getStatus({Array})
getBasePath
Get the base path of the controller.
public getBasePath({Array})
setBasePath
Set the base path for the controller.
public setBasePath({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
redirect
Generate a redirect response to redirect the browser.
public redirect({Array})
It's quite common to redirect the user to an alternative URL. This may be to forward the request to another website, forward them to an authentication page or even just remove processed request parameters from the URL to neaten the URL up.
Parameters
Parameter | Type | Description |
---|---|---|
$location | string | The URI you want to redirect to |
$saveURI | bool | Optionally save the URI so we can redirect back. See: Hazaar\Application::redirectBack() |
redirectBack
Redirect back to a URI saved during redirection.
public redirectBack({Array})
This mechanism is used with the $saveURI parameter of Hazaar\Application::redirect()
so save the current URI into the session so that once we're done processing the request somewhere else we can come back to where we were. This is useful for when a user requests a page but isn't authenticated, we can redirect them to a login page and then that page can call this Hazaar\Application::redirectBack()
method to redirect the user back to the page they were originally looking for.
Parameters
Parameter | Type | Description |
---|---|---|
$altURL | string |
getURL
Generate a URL relative to the controller.
public getURL({Array})
This is the controller relative method for generating URLs in your application. URLs generated from here are relative to the controller. For URLs that are relative to the current application see Hazaar\Application::url()
.
Parameters are dynamic and depend on what you are trying to generate.
For examples see: Generating URLs
addHelper
Add a helper to the controller.
public addHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | The helper to add to the controller. This can be a helper object, a helper class name or an array of helpers. |
$args | array | an array of arguments to pass to the helper constructor |
$alias | string | The alias to use for the helper. If not provided, the helper name will be used. |
hasHelper
Checks if a helper exists.
public hasHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | the name of the helper to check |
cacheAction
public cacheAction({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$actionName | string | |
$timeout | int | |
$private | bool |
findHelper
Find a helper class by name.
private findHelper({Array})
This method searches for view helper classes based on the given name. The search order is important because it allows apps to override built-in helpers.
Parameters
Parameter | Type | Description |
---|---|---|
$name | string | the name of the helper class to find |
getCacheKey
Get the cache key for the current action.
private getCacheKey({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$controller | string | the controller name |
$action | string | the action name |
$actionArgs | array | the action arguments |
$cacheName | string | the cache name |
cacheResponse
private cacheResponse({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$route | Route | |
$response | Response |
getCachedResponse
private getCachedResponse({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$route | Route |
Generated by Hazaar API Doc Generator