.

Ajax
[Modules]

Content view for Ajax (JSON) result data. More...

Classes

class   AjaxRenderDecorator
  Renders result as Ajax Response. More...
class   AjaxView
  Renders page as Ajax result. More...
class   ViewFactoryAjax
  Overload View Factory to create AjaxView. More...

Detailed Description

Content view for Ajax (JSON) result data.

To use the model you simply use the AjaxRenderDecorator, when defining a route

 $routes = array(
   new ExactMatchRoute('my/fancy/ajax', $this, 'my_fancy_ajax', new AjaxRenderDecorator())
 );

In the according action, you do not need to create a view. Simply set ajax_data on the PageData instance. Error return values are respected.

 public function action_my_fancy_ajax(PageData $page_data) {
   if (today_is_monday()) {
      return self::INTERNAL_ERROR; // We are on strike on mondays!
   }
   
   $page_data->ajax_data = array(
        'fishes' => 'fancy',
        'squirrels' => 'fierce'
   );
 }

This will return the following array on success (JSON encoded):

 array(
   'is_error' => false,
   'result' => array(
     'fishes' => 'fancy',
     'squirrels' => 'fierce'
   )
 )

Execpt on mondays, when it returns the error:

 array(
   'is_error' => true,
   'error' => 'Server error'
 )