/**
  * Skip loading helpers if this is a _serialize based view.
  *
  * @return void
  */
 public function loadHelpers()
 {
     if (isset($this->viewVars['_serialize'])) {
         return;
     }
     parent::loadHelpers();
 }
示例#2
0
 /**
  * Render a JSON view.
  *
  * ### Special parameters
  * `_serialize` To convert a set of view variables into a JSON response.
  *   Its value can be a string for single variable name or array for multiple
  *   names. If true all view variables will be serialized. It unset normal
  *   view template will be rendered.
  * `_jsonp` Enables JSONP support and wraps response in callback function
  *   provided in query string.
  *   - Setting it to true enables the default query string parameter "callback".
  *   - Setting it to a string value, uses the provided query string parameter
  *     for finding the JSONP callback name.
  *
  * @param string|null $view The view being rendered.
  * @param string|null $layout The layout being rendered.
  * @return string|null The rendered view.
  */
 public function render($view = null, $layout = null)
 {
     $return = parent::render($view, $layout);
     if (!empty($this->viewVars['_jsonp'])) {
         $jsonpParam = $this->viewVars['_jsonp'];
         if ($this->viewVars['_jsonp'] === true) {
             $jsonpParam = 'callback';
         }
         if (isset($this->request->query[$jsonpParam])) {
             $return = sprintf('%s(%s)', h($this->request->query[$jsonpParam]), $return);
             $this->response->type('js');
         }
     }
     return $return;
 }