PHP Class Voodoo\Core\Controller

Inheritance: use trait Voodoo\Core\Controller\TAnnotation, use trait Voodoo\Core\Controller\TPagination
Show file Open project: voodoophp/voodoo Class Usage Examples

Protected Properties

Property Type Description
$abort boolean Flag to abort the execution of a controller
$actionName string The action's name being called
$actionView The action view to use
$controllerName String The controller's name
$httpStatusCode integer The default status code
$moduleName String The module name
$namespace string The full namespace of the controller
$reflection Reflection The reflection of the called class

Public Methods

Method Description
__construct ( array $segments = [] ) final construct so no other class can override it To load something in the constructor, use init()
__destruct ( ) It's a wrap By default, when the destructor is called, it will render the views To disable view, in your controller set: $this->disableView(true)
__toString ( ) : string Return the full name of the class
actionIndex ( ) This is the index action.
catchNumericSegment ( ) : mixed To catch the first numeric value from the URL segment. ie: /music/rap/12573/Where-Have-You-Been. Will return 12573
disableView ( $bool = true ) : Controller To enable render view. on __destruct, it will render the view, otherwise it's up to the controller to launch it.
getAction ( string $action = "Index" ) : Controller Load an action by providing just the name without the Action suffix.
getActionMethodName ( ) : string Return the full name of the method
getActionName ( ) : string Return the last action name saved
getActionUrl ( ) : string Return the action url
getApplicationDir ( ) : string Get the application
getBaseDir ( ) : string Return the root dir relative to the Application dir Use it to include files, or get relative path of file
getBaseUrl ( ) : string Return the root url which will properly format the url so it adds or not ? to make the relative link
getConfig ( type $key = null ) : mixed To access config info
getControllerName ( ) : string Return the controller's name
getControllerUrl ( ) : string Return the url for the controller
getIp ( ) : string Return the user agent ip
getModuleDir ( ) : string Get the module directory
getModuleName ( ) : string Return the module's name
getModuleNamespace ( )
getModuleUrl ( ) : string Return the URL of the module
getParam ( string $key = null, mixed $default = null ) : mixed Get POST or GET param
getParams ( ) : Array Return all the request params of GET and POST
getRequestURI ( ) : string To get the request uri. It includes everything in the URI
getSegment ( $key = null, $offset ) : mixed Segements are part of the URL separated by / ie: /gummy/bear/?q=hello 'gummy' and 'bear' are segments.
getSiteUrl ( ) : string Return the site url itself
isAjax ( ) : boolean CHeck request if it's an ajax request
isGet ( ) : boolean Bool if the request method is a GET
isPost ( ) : boolean Bool if the request method is a POST
redirect ( $url = "", integer $httpCode = 302 ) To redirect the page to a new page
setHttpCode ( integer $code = 200 ) : Voodoo\Core\Controller Set the http status code
toDate ( mixed $datetime, $format = null ) : string Return a formatted date
toFriendlyUrl ( type $url ) : string Return a string to friendly url

Protected Methods

Method Description
_exit ( ) : void To completely exit the application just like calling exit().
abort ( ) : Controller Abort the execution of finalize() and renderView() of the application in __destruct
afterAction ( ) : Controller afterAction() Execute the method after the Action is executed
beforeAction ( ) : Controller beforeAction() Execute the method before the Action is executed
finalize ( ) : Controller finalize() Code to excute before rendering
forwardTo ( string $controllerName, array $params = [] ) : Controller forward, like getController, forward the current controller to a new controller and allows it to render the view, while it deactivate the current controller view.
getActionView ( ) : type Return the action view
getController ( $controllerName, array $params = [] ) : Voodoo\Core\controller To access another controller without rendering it
init ( ) : Controller init() __construct is and can't be overriden by any child class init() lets you put code that could be executed in __construct()
renderView ( boolean $echoView = true ) : boolean | string To render the controller's view
setActionName ( string $action ) Set the action name
setActionView ( type $view ) : Controller Set the action view to be displayed
view ( array $dataModel = null ) : Voodoo\Core\View Return the View instance
viewExists ( ) : boolean Verify if the view directory exists

Private Methods

Method Description
dasherizeUrl ( type $str ) : string Dasherize part for a url
getParentNamespace ( type $namespace ) : string Return the parent namespace

Method Details

__construct() final public method

final construct so no other class can override it To load something in the constructor, use init()
final public __construct ( array $segments = [] )
$segments array

__destruct() final public method

It's a wrap By default, when the destructor is called, it will render the views To disable view, in your controller set: $this->disableView(true)
final public __destruct ( )

__toString() public method

Return the full name of the class
public __toString ( ) : string
return string

_exit() final protected method

__destruct will be invoked, but will not finalize() and renderView() Calling PHP exit() will still cause finalize() and renderView() to execute
final protected _exit ( ) : void
return void

abort() final protected method

Abort the execution of finalize() and renderView() of the application in __destruct
final protected abort ( ) : Controller
return Controller

actionIndex() abstract public method

It is loaded by default or an action is missing Every controller requires it
abstract public actionIndex ( )

afterAction() protected method

afterAction() Execute the method after the Action is executed
protected afterAction ( ) : Controller
return Controller

beforeAction() protected method

beforeAction() Execute the method before the Action is executed
protected beforeAction ( ) : Controller
return Controller

catchNumericSegment() public method

To catch the first numeric value from the URL segment. ie: /music/rap/12573/Where-Have-You-Been. Will return 12573
public catchNumericSegment ( ) : mixed
return mixed (int | null)

disableView() public method

To enable render view. on __destruct, it will render the view, otherwise it's up to the controller to launch it.
public disableView ( $bool = true ) : Controller
return Controller

finalize() protected method

finalize() Code to excute before rendering
protected finalize ( ) : Controller
return Controller

forwardTo() protected method

All the settings and params will be forwarded to the new controller
protected forwardTo ( string $controllerName, array $params = [] ) : Controller
$controllerName string
$params array
return Controller

getAction() public method

Its purpose is to set the action to be rendered. You still can access the method the normal way $this->action_index i.e $this->getAction("index");
public getAction ( string $action = "Index" ) : Controller
$action string - The action name without Action as suffix. ie: action_index() = getAction("index")
return Controller NOTE: actions make use of the annotations @action_view @use_layout @request @format

getActionMethodName() public method

Return the full name of the method
public getActionMethodName ( ) : string
return string

getActionName() public method

Return the last action name saved
public getActionName ( ) : string
return string

getActionUrl() public method

Return the action url
public getActionUrl ( ) : string
return string

getActionView() protected method

Return the action view
protected getActionView ( ) : type
return type

getApplicationDir() public method

Get the application
public getApplicationDir ( ) : string
return string

getBaseDir() public method

Return the root dir relative to the Application dir Use it to include files, or get relative path of file
public getBaseDir ( ) : string
return string

getBaseUrl() public method

Return the root url which will properly format the url so it adds or not ? to make the relative link
public getBaseUrl ( ) : string
return string

getConfig() public method

To access config info
public getConfig ( type $key = null ) : mixed
$key type
return mixed

getController() protected method

To access another controller without rendering it
protected getController ( $controllerName, array $params = [] ) : Voodoo\Core\controller
$params array
return Voodoo\Core\controller

getControllerName() public method

Return the controller's name
public getControllerName ( ) : string
return string

getControllerUrl() public method

Return the url for the controller
public getControllerUrl ( ) : string
return string

getIp() public method

Return the user agent ip
public getIp ( ) : string
return string

getModuleDir() public method

Get the module directory
public getModuleDir ( ) : string
return string

getModuleName() public method

Return the module's name
public getModuleName ( ) : string
return string

getModuleNamespace() public method

public getModuleNamespace ( )

getModuleUrl() public method

Return the URL of the module
public getModuleUrl ( ) : string
return string

getParam() public method

Get POST or GET param
public getParam ( string $key = null, mixed $default = null ) : mixed
$key string
$default mixed
return mixed

getParams() public method

Return all the request params of GET and POST
public getParams ( ) : Array
return Array

getRequestURI() public method

To get the request uri. It includes everything in the URI
public getRequestURI ( ) : string
return string

getSegment() public method

Segements are part of the URL separated by / ie: /gummy/bear/?q=hello 'gummy' and 'bear' are segments.
public getSegment ( $key = null, $offset ) : mixed
return mixed

getSiteUrl() public method

Return the site url itself
public getSiteUrl ( ) : string
return string

init() protected method

init() __construct is and can't be overriden by any child class init() lets you put code that could be executed in __construct()
protected init ( ) : Controller
return Controller

isAjax() public method

CHeck request if it's an ajax request
public isAjax ( ) : boolean
return boolean

isGet() public method

Bool if the request method is a GET
public isGet ( ) : boolean
return boolean

isPost() public method

Bool if the request method is a POST
public isPost ( ) : boolean
return boolean

redirect() public method

To redirect the page to a new page
public redirect ( $url = "", integer $httpCode = 302 )
$httpCode integer

renderView() protected method

To render the controller's view
protected renderView ( boolean $echoView = true ) : boolean | string
$echoView boolean - to print the view or just return it
return boolean | string | string

setActionName() protected method

Set the action name
protected setActionName ( string $action )
$action string

setActionView() protected method

Set the action view to be displayed
protected setActionView ( type $view ) : Controller
$view type
return Controller

setHttpCode() public method

Set the http status code
public setHttpCode ( integer $code = 200 ) : Voodoo\Core\Controller
$code integer
return Voodoo\Core\Controller

toDate() public method

Return a formatted date
public toDate ( mixed $datetime, $format = null ) : string
$datetime mixed
return string

toFriendlyUrl() public method

Return a string to friendly url
public toFriendlyUrl ( type $url ) : string
$url type
return string

view() protected method

Return the View instance
protected view ( array $dataModel = null ) : Voodoo\Core\View
$dataModel array - Data model to assign to the view
return Voodoo\Core\View

viewExists() protected method

Verify if the view directory exists
protected viewExists ( ) : boolean
return boolean

Property Details

$abort protected property

Flag to abort the execution of a controller
protected bool $abort
return boolean

$actionName protected property

The action's name being called
protected string $actionName
return string

$actionView protected property

The action view to use
protected $actionView

$controllerName protected property

The controller's name
protected String $controllerName
return String

$httpStatusCode protected property

The default status code
protected int $httpStatusCode
return integer

$moduleName protected property

The module name
protected String $moduleName
return String

$namespace protected property

The full namespace of the controller
protected string $namespace
return string

$reflection protected property

The reflection of the called class
protected Reflection $reflection
return Reflection