ZenMagick 0.9.6


org.zenmagick.rp.ajax.ZMAjaxController

Class ZMAjaxController

ZMObject
|
+--ZMController
|
+--ZMAjaxController

public class ZMAjaxController
extends ZMController

Request controller for ajax requests.

Uses native PHP function json_encode.

Author:
DerManoMann
Version:
$Id: ZMAjaxController.php 2173 2009-04-22 04:55:11Z dermanomann $

Constructor Summary

ZMAjaxController(string id)

Create new instance.

Method Summary
array

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

Flattens any given object.

ZMView

process()

Process a HTTP request.

ZMView

processGet()

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.rp.ZMController
exportGlobal, findView, getFormBean, getGlobal, getGlobals, getId, getView, handleRequest, isFormSubmit, process, processGet, processPost, setContentType, setId, setView, validate, validateFormBean
Methods inherited from org.zenmagick.ZMObject
attachMethod, get, getAttachedMethods, getPropertyNames, set, singleton

Constructor Detail

ZMAjaxController

public ZMAjaxController(string id)

Create new instance.

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

Method Detail

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.

process

public ZMView process()

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.

processGet

public ZMView processGet()

Process a HTTP GET request.

Just return null.

/

Returns:
A ZMView that handles presentation or null * if the controller generates the contents itself.

setJSONHeader

public void setJSONHeader(string json)

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

Parameters:
json - The JSON data.

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.6