Extends
lithium\core\Object
Called by the Dispatcher class to invoke an action.
Parameters
- object $request The request object with URL and HTTP info for dispatching this action.
- array $dispatchParams The array of parameters that will be passed to the action.
- array $options The dispatch options for this action.
Returns
object Returns the response object associated with this controller.Source
public function __invoke($request, $dispatchParams, array $options = array()) {
$render =& $this->_render;
$params = compact('request', 'dispatchParams', 'options');
return $this->_filter(__METHOD__, $params, function($self, $params) use (&$render) {
$dispatchParams = $params['dispatchParams'];
$action = isset($dispatchParams['action']) ? $dispatchParams['action'] : 'index';
$args = isset($dispatchParams['args']) ? $dispatchParams['args'] : array();
$result = null;
if (substr($action, 0, 1) == '_' || method_exists(__CLASS__, $action)) {
throw new DispatchException('Attempted to invoke a private method.');
}
if (!method_exists($self, $action)) {
throw new DispatchException("Action `{$action}` not found.");
}
$render['template'] = $render['template'] ?: $action;
if ($result = $self->invokeMethod($action, $args)) {
if (is_string($result)) {
$self->render(array('text' => $result));
return $self->response;
}
if (is_array($result)) {
$self->set($result);
}
}
if (!$render['hasRendered'] && $render['auto']) {
$self->render();
}
return $self->response;
});
}