gyro/modules/ajax/start.inc.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * @defgroup Ajax 00004 * @ingroup Modules 00005 * 00006 * Content view for Ajax (JSON) result data 00007 * 00008 * To use the model you simply use the AjaxRenderDecorator, when defining a route 00009 * 00010 * @code 00011 * $routes = array( 00012 * new ExactMatchRoute('my/fancy/ajax', $this, 'my_fancy_ajax', new AjaxRenderDecorator()) 00013 * ); 00014 * @endcode 00015 * 00016 * In the according action, you do not need to create a view. Simply set ajax_data on the PageData 00017 * instance. Error return values are respected. 00018 * 00019 * @code 00020 * public function action_my_fancy_ajax(PageData $page_data) { 00021 * if (today_is_monday()) { 00022 * return self::INTERNAL_ERROR; // We are on strike on mondays! 00023 * } 00024 * 00025 * $page_data->ajax_data = array( 00026 * 'fishes' => 'fancy', 00027 * 'squirrels' => 'fierce' 00028 * ); 00029 * } 00030 * @endcode 00031 * 00032 * This will return the following array on success (JSON encoded): 00033 * 00034 * @code 00035 * array( 00036 * 'is_error' => false, 00037 * 'result' => array( 00038 * 'fishes' => 'fancy', 00039 * 'squirrels' => 'fierce' 00040 * ) 00041 * ) 00042 * @endcode 00043 * 00044 * Execpt on mondays, when it returns the error: 00045 * 00046 * @code 00047 * array( 00048 * 'is_error' => true, 00049 * 'error' => 'Server error' 00050 * ) 00051 * @endcode 00052 */ 00053 00054 // Register our views 00055 ViewFactory::set_implementation(new ViewFactoryAjax());