Simplify AJAX context switching based on requested format

uses
category Zend
package Zend_Controller
subpackage Zend_Controller_Action_Helper
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Controller_Action_Helper_ContextSwitch

 Methods

Constructor

__construct() : void

Add HTML context

inherited_from \Zend_Controller_Action_Helper_ContextSwitch::__construct()

Constructor

__construct(array|\Zend_Config $options = null) : void
Inherited

Parameters

$options

array\Zend_Config

Add one or more contexts to an action

addActionContext(string $action, string|array $context) : \Zend_Controller_Action_Helper_ContextSwitch | void
Inherited

Parameters

$action

string

$context

stringarray

Returns

\Zend_Controller_Action_Helper_ContextSwitchvoidProvides a fluent interface

Add multiple action/context pairs at once

addActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$contexts

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Add new context

addContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

Context type

$spec

array

Context specification

Exceptions

\Zend_Controller_Action_Exception

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Add multiple contexts

addContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$contexts

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Add header to context

addHeader(string $context, string $header, string $content) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

$header

string

$content

string

Exceptions

\Zend_Controller_Action_Exception

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Add multiple headers at once for a given context

addHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

$headers

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Clear all contexts for a given controller action or all actions

clearActionContexts(string $action = null) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$action

string

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Clear all callbacks for a given context

clearCallbacks(string $context) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Remove all contexts

clearContexts() : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Clear all headers for a given context

clearHeaders(string $context) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Strategy pattern: return object

direct() : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Get contexts for a given action or all actions in the controller

getActionContexts(string $action = null) : array
Inherited

Parameters

$action

string

Returns

array

Retrieve current action controller

getActionController() : \Zend_Controller_Action
Inherited

Returns

\Zend_Controller_Action

Retrieve auto layout disable flag

getAutoDisableLayout() : boolean
Inherited

Returns

boolean

Get JSON context auto-serialization flag

getAutoJsonSerialization() : boolean
Inherited

Returns

boolean

Get a single callback for a given context and trigger

getCallback(string $context, string $trigger) : string | array | null
Inherited

Parameters

$context

string

$trigger

string

Returns

stringarraynull

Get all callbacks for a given context

getCallbacks(string $context) : array
Inherited

Parameters

$context

string

Returns

array

Retrieve context specification

getContext(string $context) : array | null
Inherited

Parameters

$context

string

Returns

arraynull

Return context format request parameter name

getContextParam() : string
Inherited

Returns

string

Retrieve context definitions

getContexts() : array
Inherited

Returns

array

Return current context, if any

getCurrentContext() : null | string
Inherited

Returns

nullstring

Return default context

getDefaultContext() : string
Inherited

Returns

string

Retrieve front controller instance

getFrontController() : \Zend_Controller_Front
Inherited

Returns

\Zend_Controller_Front

Retrieve context header

getHeader(string $context, string $header) : string | null
Inherited

Returns the value of a given header for a given context type

Parameters

$context

string

$header

string

Returns

stringnull

Retrieve context headers

getHeaders(string $context) : array
Inherited

Returns all headers for a context as key/value pairs

Parameters

$context

string

Returns

array

getName()

getName() : string
Inherited

Returns

string

getRequest() -

getRequest() : \Zend_Controller_Request_Abstract
Inherited

Returns

\Zend_Controller_Request_Abstract$request

getResponse() -

getResponse() : \Zend_Controller_Response_Abstract
Inherited

Returns

\Zend_Controller_Response_Abstract$response

Retrieve suffix for given context type

getSuffix(string $type) : string
Inherited

Parameters

$type

string

Context type

Exceptions

\Zend_Controller_Action_Exception

Returns

string

Does a particular controller action have the given context(s)?

hasActionContext(string $action, string|array $context) : boolean
Inherited

Parameters

$action

string

$context

stringarray

Exceptions

\Zend_Controller_Action_Exception

Returns

boolean

Does the given context exist?

hasContext(string $context, boolean $throwException = false) : boolean
Inherited

Parameters

$context

string

$throwException

boolean

Exceptions

\Zend_Controller_Action_Exception if context does not exist and throwException is true

Returns

boolean

Hook into action controller initialization

init() : void
Inherited

Initialize AJAX context switching

initContext(string $format = null) : void

Checks for XHR requests; if detected, attempts to perform context switch.

inherited_from \Zend_Controller_Action_Helper_ContextSwitch::initContext()

Parameters

$format

string

Initialize context detection and switching

initContext(mixed $format = null) : void
Inherited

Parameters

$format

mixed

Exceptions

\Zend_Controller_Action_Exception

JSON context extra initialization

initJsonContext() : void
Inherited

Turns off viewRenderer auto-rendering

Hook into action controller postDispatch() workflow

postDispatch() : void
Inherited

JSON post processing

postJsonContext() : void
Inherited

JSON serialize view variables to response body

Hook into action controller preDispatch() workflow

preDispatch() : void
Inherited

Remove one or more contexts for a given controller action

removeActionContext(string $action, string|array $context) : boolean
Inherited

Parameters

$action

string

$context

stringarray

Returns

boolean

Clear a callback for a given context and trigger

removeCallback(string $context, string $trigger) : boolean
Inherited

Parameters

$context

string

$trigger

string

Returns

boolean

Remove a context

removeContext(string $context) : boolean
Inherited

Parameters

$context

string

Returns

boolean

Remove a single header from a context

removeHeader(string $context, string $header) : boolean
Inherited

Parameters

$context

string

$header

string

Returns

boolean

Set a context as available for a given controller action

setActionContext(string $action, string|array $context) : \Zend_Controller_Action_Helper_ContextSwitch | void
Inherited

Parameters

$action

string

$context

stringarray

Returns

\Zend_Controller_Action_Helper_ContextSwitchvoidProvides a fluent interface

Overwrite and set multiple action contexts at once

setActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$contexts

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

setActionController()

setActionController(\Zend_Controller_Action $actionController = null) : \Zend_Controller_ActionHelper_Abstract
Inherited

Parameters

$actionController

\Zend_Controller_Action

Returns

\Zend_Controller_ActionHelper_AbstractProvides a fluent interface

Set flag indicating if layout should be disabled

setAutoDisableLayout(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Should JSON contexts auto-serialize?

setAutoJsonSerialization(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set a callback for a given context and trigger

setCallback(string $context, string $trigger, string|array $callback) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

$trigger

string

$callback

stringarray

Exceptions

\Zend_Controller_Action_Exception

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set callbacks for a given context

setCallbacks(string $context, array $callbacks) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Callbacks should be in trigger/callback pairs.

Parameters

$context

string

$callbacks

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set object state from config object

setConfig(\Zend_Config $config) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$config

\Zend_Config

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Overwrite existing context

setContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

Context type

$spec

array

Context specification

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set name of parameter to use when determining context format

setContextParam(string $name) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$name

string

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set multiple contexts, after first removing all

setContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$contexts

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Indicate default context to use when no context format provided

setDefaultContext(string $type) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$type

string

Exceptions

\Zend_Controller_Action_Exception

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Customize response header to use when switching context

setHeader($context, string $header, string $content) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Passing an empty header value to the setters disables the response header.

Parameters

$context

$header

string

Header to set

$content

string

Header content

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set multiple headers at once for a given context

setHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$context

string

$headers

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Configure object from array of options

setOptions(array $options) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$options

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Customize view script suffix to use when switching context.

setSuffix(string $context, string $suffix, boolean $prependViewRendererSuffix = true) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Passing an empty suffix value to the setters disables the view script suffix change.

Parameters

$context

string

Context type for which to set suffix

$suffix

string

Suffix to use

$prependViewRendererSuffix

boolean

Whether or not to prepend the new suffix to the viewrenderer suffix

Exceptions

\Zend_Controller_Action_Exception

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Retrieve ViewRenderer

_getViewRenderer() : \Zend_Controller_Action_Helper_ViewRenderer
Inherited

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set callbacks from array of context => callbacks pairs

_setCallbacks(array $options) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$options

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set headers from context => headers pairs

_setHeaders(array $options) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$options

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Set suffix from array

_setSuffix(array $spec) : \Zend_Controller_Action_Helper_ContextSwitch
Inherited

Parameters

$spec

array

Returns

\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface

Validate trigger and return in normalized form

_validateTrigger(string $trigger) : string
Inherited

Parameters

$trigger

string

Exceptions

\Zend_Controller_Action_Exception

Returns

string

 Properties

 

$_actionController

$_actionController : \Zend_Controller_Action

Default

null
 

JSON auto-serialization flag

$_autoJsonSerialization : boolean

Default

true
 

Controller property to utilize for context switching

$_contextKey : string

Default

'ajaxable'
inherited_from \Zend_Controller_Action_Helper_ContextSwitch::_contextKey
 

Controller property key to utilize for context switching

$_contextKey : string

Default

'contexts'
 

Request parameter containing requested context

$_contextParam : string

Default

'format'
 

Supported contexts

$_contexts : array

Default

array()
 

Current context

$_currentContext : string

Default

 

Default context (xml)

$_defaultContext : string

Default

'xml'
 

Whether or not to disable layouts when switching contexts

$_disableLayout : boolean

Default

true
 

$_frontController

$_frontController : mixed

Default

null
 

Methods that require special configuration

$_specialConfig : array

Default

array('setSuffix', 'setHeaders', 'setCallbacks')
 

Methods that are not configurable via setOptions and setConfig

$_unconfigurable : array

Default

array('setOptions', 'setConfig', 'setHeader', 'setCallback', 'setContext', 'setActionContext', 'setActionContexts')
 

$_viewRenderer

$_viewRenderer : \Zend_Controller_Action_Helper_ViewRenderer

Default

 

Original view suffix prior to detecting context switch

$_viewSuffixOrig : string

Default

 Constants

 

Trigger type constants

TRIGGER_INIT = 'TRIGGER_INIT' 
 

TRIGGER_POST

TRIGGER_POST = 'TRIGGER_POST'