ZenMagick 0.9.10


org.zenmagick.mvc.controller\ZMAjaxController
mvc\controller\ZMAjaxController.php at line 33

Class ZMAjaxController

ZMObject
└─ZMController
└─ZMAjaxController

public class ZMAjaxController
extends ZMController

Request controller for ajax requests.

Uses native PHP function json_encode.

Author:
DerManoMann
Deprecated:
use ZMRpcController instead

Method Summary
void

__construct(string requestId)

Create new instance.

array

flattenObject(mixed obj, mixed properties, function formatter, array methods)

Flattens any given object.

ZMView

process(ZMRequest request)

Process a HTTP request.

ZMView

processGet(ZMRequest request)

Process a HTTP GET request.

void

setJSONHeader(string json)

Set JSON response header ('X-JSON').

string

toJSON(mixed obj)

Serialize object to JSON.

Methods inherited from org.zenmagick.mvc.controller\ZMController
__construct, findView, getFormData, getId, getView, getViewData, isAjax, isFormSubmit, preProcess, process, processGet, processPost, setContentType, setId, setView, validate, validateFormData, validateSession
Methods inherited from org.zenmagick.core\ZMObject
__construct, attachMethod, get, getAttachedMethods, getProperties, getPropertyNames, set, singleton

Method Detail

mvc\controller\ZMAjaxController.php at line 38

__construct

public void __construct(string requestId)

Create new instance.

Parameters:
requestId - Optional requestId; default is null to use the request id.

mvc\controller\ZMAjaxController.php at line 124

flattenObject

public array flattenObject(mixed obj, mixed properties, function formatter, array methods)

Flattens any given object.

Criteria for the included data is the ZenMagick naming convention that access methods start with either get, is or has.

If the given object is an array, all elements will be converted, too. Generally speaking, this method works recursively. Arrays are preserved, array values, in turn, will be flattened.

The methods array may contain nested arrays to allow recursiv method mapping. The Ajax product controller is a good example for this.

Parameters:
obj - The object.
methods - Optional list of methods to include as properties.
formatter - Optional formatting method for all values; signature is formatter($obj, $name, $value).
Returns:
Associative array of methods values.
Deprecated:
Use ZMAjaxUtils::flattenObject instead.

mvc\controller\ZMAjaxController.php at line 72

process

public ZMView process(ZMRequest request)

Process a HTTP request.

This implementation will delegate request handling based on the method parameter in the request. If no method is found, the default parent process() implementation will be called.

Also, if the passed method is not found, the controller will try to resolve the method by appending the configured ajaxFormat string. So, if, for example, the method is getCountries and ajaxFormat is JSON, the controller will first look for getCountries and then for getCountriesJSON.

Returns:
A ZMView instance or null.
Parameters:
request - The request to process.

mvc\controller\ZMAjaxController.php at line 54

processGet

public ZMView processGet(ZMRequest request)

Process a HTTP GET request.

Just return null.

Parameters:
request - The request to process.
Returns:
A ZMView that handles presentation or null if the controller generates the contents itself.

mvc\controller\ZMAjaxController.php at line 101

setJSONHeader

public void setJSONHeader(string json)

Set JSON response header ('X-JSON').

Parameters:
json - The JSON data.

mvc\controller\ZMAjaxController.php at line 134

toJSON

public string toJSON(mixed obj)

Serialize object to JSON.

Parameters:
obj - The object to serialize; can also be an array of objects.
Returns:
The given object as JSON.

ZenMagick 0.9.10