abstract class Controller_Abstract (View source)

\Yaf\Controller_Abstract is the heart of Yaf's system. MVC stands for Model-View-Controller and is a design pattern targeted at separating application logic from display logic.


Every custom controller shall inherit \Yaf\Controller_Abstract.


You will find that you can not define __construct function for your custom controller, thus, \Yaf\Controller_Abstract provides a magic method: \Yaf\Controller_Abstract::init().


If you have defined a init() method in your custom controller, it will be called as long as the controller was instantiated.


Action may have arguments, when a request coming, if there are the same name variable in the request parameters(see \Yaf\Request_Abstract::getParam()) after routed, Yaf will pass them to the action method (see \Yaf\Action_Abstract::execute()).


Note:

These arguments are directly fetched without filtering, it should be carefully processed before use them.

Properties

array $actions
protected string $_module
protected string $_name
protected Request_Abstract $_request
protected Response_Abstract $_response
protected array $_invoke_args
protected View_Interface $_view

Methods

string
render(string $tpl, array $parameters = null)

No description

bool
display(string $tpl, array $parameters = null)

No description

getRequest()

retrieve current request object

getResponse()

retrieve current response object

string
getModuleName()

get the controller's module name

getView()

retrieve view engine

initView(array $options = null) deprecated

No description

bool
setViewpath(string $view_directory)

No description

string
getViewpath()

No description

bool
forward(string $module, string $controller = null, string $action = null, array $parameters = null)

forward current execution process to other action.


Note:

this method doesn't switch to the destination action immediately, it will take place after current flow finish.


Notice, there are 3 available method signatures:

\Yaf\Controller_Abstract::forward ( string $module , string $controller , string $action [, array $parameters ] )

\Yaf\Controller_Abstract::forward ( string $controller , string $action [, array $parameters ] )

\Yaf\Controller_Abstract::forward ( string $action [, array $parameters ] )

bool
redirect(string $url)

redirect to a URL by sending a 302 header

array
getInvokeArgs()

No description

mixed|null
getInvokeArg(string $name)

No description

init()

\Yaf\Controller_Abstract::__construct() is final, which means users can not override it. but users can define \Yaf\Controller_Abstract::init(), which will be called after controller object is instantiated.

__construct(Request_Abstract $request, Response_Abstract $response, View_Interface $view, array $invokeArgs = null)

\Yaf\Controller_Abstract::__construct() is final, which means it can not be overridden. You may want to see \Yaf\Controller_Abstract::init() instead.

Details

protected string render(string $tpl, array $parameters = null)

No description

Parameters

string $tpl
array $parameters

Return Value

string

protected bool display(string $tpl, array $parameters = null)

No description

Parameters

string $tpl
array $parameters

Return Value

bool

Request_Abstract getRequest()

retrieve current request object

Return Value

Request_Abstract

Response_Abstract getResponse()

retrieve current response object

Return Value

Response_Abstract

string getModuleName()

get the controller's module name

Return Value

string

View_Interface getView()

retrieve view engine

Return Value

View_Interface

Response_Abstract initView(array $options = null) deprecated

deprecated not_implemented

No description

Parameters

array $options

Return Value

Response_Abstract

bool setViewpath(string $view_directory)

No description

Parameters

string $view_directory

Return Value

bool

string getViewpath()

No description

Return Value

string

bool forward(string $module, string $controller = null, string $action = null, array $parameters = null)

forward current execution process to other action.


Note:

this method doesn't switch to the destination action immediately, it will take place after current flow finish.


Notice, there are 3 available method signatures:

\Yaf\Controller_Abstract::forward ( string $module , string $controller , string $action [, array $parameters ] )

\Yaf\Controller_Abstract::forward ( string $controller , string $action [, array $parameters ] )

\Yaf\Controller_Abstract::forward ( string $action [, array $parameters ] )

Parameters

string $module

destination module name, if NULL was given, then default module name is assumed

string $controller

destination controller name

string $action

destination action name

array $parameters

calling arguments

Return Value

bool

return FALSE on failure

bool redirect(string $url)

redirect to a URL by sending a 302 header

Parameters

string $url

a location URL

Return Value

bool

array getInvokeArgs()

No description

Return Value

array

mixed|null getInvokeArg(string $name)

No description

Parameters

string $name

Return Value

mixed|null

init()

\Yaf\Controller_Abstract::__construct() is final, which means users can not override it. but users can define \Yaf\Controller_Abstract::init(), which will be called after controller object is instantiated.

final __construct(Request_Abstract $request, Response_Abstract $response, View_Interface $view, array $invokeArgs = null)

\Yaf\Controller_Abstract::__construct() is final, which means it can not be overridden. You may want to see \Yaf\Controller_Abstract::init() instead.

Parameters

Request_Abstract $request
Response_Abstract $response
View_Interface $view
array $invokeArgs

See also

Controller_Abstract::init