PHP Class Tools\Controller\Component\CommonComponent

Author: Mark Scherer
Inheritance: extends Shim\Controller\Component\Component
显示文件 Open project: dereuromark/cakephp-tools

Public Methods

Method Description
autoPostRedirect ( mixed $whereTo, boolean $conditionalAutoRedirect = true, integer $status = 302 ) : Response Combine auto with post also allows whitelisting certain actions for autoRedirect (use Controller::$autoRedirectActions)
autoRedirect ( mixed $whereTo, boolean $allowSelf = false, integer $status = 302 ) : Response Smart Referer Redirect - will try to use an existing referer first otherwise it will use the default url
completeRedirect ( mixed | null $url = null, integer | null $status = 302 ) : Response Automatically add missing URL parts of the current URL including - querystring (especially for 3.x then) - passed params
currentUrl ( boolean $asString = false ) : mixed Returns current url (with all missing params automatically added).
defaultUrlParams ( ) : array Returns defaultUrlParams including configured prefixes.
forceCache ( integer $seconds = HOUR ) : void Set headers to cache this request.
getPassedParam ( mixed $var, mixed $default = null ) : mixed Used to get the value of a passed param.
isForeignReferer ( string | null $ref = null ) : boolean Referrer checking (where does the user come from) Only returns true for a valid external referrer.
isPosted ( ) : boolean Convenience method to check on POSTED data.
listActions ( ) : array List all direct actions of a controller
loadComponent ( string $component, array $config = [], boolean $callbacks = true ) : void Add component just in time (inside actions - only when needed) aware of plugins and config array (if passed)
loadHelper ( mixed $helpers = [] ) : void Add helper just in time (inside actions - only when needed) aware of plugins
postRedirect ( mixed $whereTo, integer $status = 302 ) : Response Should be a 303, but: Note: Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303.
startup ( Cake\Event\Event $event ) : void For this helper the controller has to be passed as reference for manual startup with $disableStartup = true (requires this to be called prior to any other method)

Method Details

autoPostRedirect() public method

Combine auto with post also allows whitelisting certain actions for autoRedirect (use Controller::$autoRedirectActions)
public autoPostRedirect ( mixed $whereTo, boolean $conditionalAutoRedirect = true, integer $status = 302 ) : Response
$whereTo mixed URL
$conditionalAutoRedirect boolean false to skip whitelisting
$status integer
return Cake\Network\Response

autoRedirect() public method

Smart Referer Redirect - will try to use an existing referer first otherwise it will use the default url
public autoRedirect ( mixed $whereTo, boolean $allowSelf = false, integer $status = 302 ) : Response
$whereTo mixed URL
$allowSelf boolean if redirect to the same controller/action (url) is allowed
$status integer
return Cake\Network\Response

completeRedirect() public method

Automatically add missing URL parts of the current URL including - querystring (especially for 3.x then) - passed params
public completeRedirect ( mixed | null $url = null, integer | null $status = 302 ) : Response
$url mixed | null
$status integer | null
return Cake\Network\Response

currentUrl() public method

Necessary for Router::url() and comparison of urls to work.
public currentUrl ( boolean $asString = false ) : mixed
$asString boolean Defaults to false = array
return mixed URL

defaultUrlParams() public static method

Returns defaultUrlParams including configured prefixes.
public static defaultUrlParams ( ) : array
return array URL params

forceCache() public method

Opposite of Controller::disableCache()
public forceCache ( integer $seconds = HOUR ) : void
$seconds integer
return void

getPassedParam() public method

Used to get the value of a passed param.
public getPassedParam ( mixed $var, mixed $default = null ) : mixed
$var mixed
$default mixed
return mixed

isForeignReferer() public method

Referrer checking (where does the user come from) Only returns true for a valid external referrer.
public isForeignReferer ( string | null $ref = null ) : boolean
$ref string | null Referer
return boolean Success

isPosted() public method

Doesn't matter if it's POST, PUT or PATCH. Note that you can also use request->is(array('post', 'put', 'patch') directly.
public isPosted ( ) : boolean
return boolean If it is of type POST/PUT/PATCH

listActions() public method

List all direct actions of a controller
public listActions ( ) : array
return array Actions

loadComponent() public method

Add component just in time (inside actions - only when needed) aware of plugins and config array (if passed)
public loadComponent ( string $component, array $config = [], boolean $callbacks = true ) : void
$component string Component
$config array
$callbacks boolean (defaults to true)
return void

loadHelper() public method

Add helper just in time (inside actions - only when needed) aware of plugins
Deprecation: In 3.x, but kept for easier migration for now. Will be removed in the future.
public loadHelper ( mixed $helpers = [] ) : void
$helpers mixed (single string or multiple array)
return void

postRedirect() public method

TODO: change to 303 with backwardscompatability for older browsers...
See also: http://en.wikipedia.org/wiki/Post/Redirect/Get
public postRedirect ( mixed $whereTo, integer $status = 302 ) : Response
$whereTo mixed URL
$status integer
return Cake\Network\Response

startup() public method

For this helper the controller has to be passed as reference for manual startup with $disableStartup = true (requires this to be called prior to any other method)
public startup ( Cake\Event\Event $event ) : void
$event Cake\Event\Event
return void