Beispiel #1
0
 public function after()
 {
     parent::after();
     if ($this->auto_render === TRUE) {
         $styles = array();
         $scripts = array();
         $this->template->styles = array_merge($this->template->styles, $styles);
         $this->template->scripts = array_merge($this->template->scripts, $scripts);
         unset($styles, $scripts);
         $this->template->set_global('app_config', $this->app_config);
         // Заносим в переменную messages данные из сессии
         //                $this->template->messages = View::factory('global/messages', array(
         //                     'messages' => Session::instance()->get_once('flash_messages')
         //                ));
         $this->response->body($this->template->render());
     } elseif ($this->request->is_ajax() === TRUE) {
         // И параметр json содержит данные
         if ($this->json !== NULL) {
             if (is_array($this->json) and !isset($this->json['status'])) {
                 $this->json['status'] = FALSE;
             }
             // То в темплейте мы выводим не шаблон, а кодированные в json format данные
             $this->template = json_encode($this->json);
         }
         $this->response->body($this->template);
     }
 }
Beispiel #2
0
 /**
  * Assigns the template [View] as the request response.
  */
 public function after()
 {
     parent::after();
     if ($this->auto_render === TRUE) {
         if ($this->request->is_ajax() === TRUE or $this->json !== NULL) {
             if ($this->json !== NULL) {
                 if (is_array($this->json) and !isset($this->json['status'])) {
                     $this->json['status'] = TRUE;
                 }
                 $this->response->headers('Content-type', 'application/json');
                 $this->template = json_encode($this->json);
             } else {
                 $this->only_content = TRUE;
             }
         } else {
             $js_string = '';
             foreach ($this->template_js_params as $var => $value) {
                 $value = json_encode($value);
                 $js_string .= "var {$var} = {$value};\n";
             }
             Assets::group('global', 'js_params', '<script type="text/javascript">' . $js_string . '</script>', 'global');
         }
         if ($this->only_content) {
             $this->template = $this->template->content;
         }
         if ($this->template instanceof View) {
             $this->template->set('request', $this->request);
         }
         Observer::notify('template_before_render', $this->request);
         $this->response->body($this->template);
     }
 }
Beispiel #3
0
 public function after()
 {
     // http://kohanaframework.org/3.3/guide-api/Response#headers
     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
     $this->response->headers(array('Content-Type' => 'text/' . $this->_dataType, 'Pragma' => 'no-cache', 'Cache-Control' => 'no-store, no-cache, must-revalidate'));
     // TODO: Add translation of $ this->_result format $_dataType, will likely have to write helper
     // TODO: Добавить преобразование результата  $this->_result в формат $_dataType, скорее всего придется писать хэлпер
     switch ($this->_dataType) {
         case 'json':
             $this->_result = json_encode($this->_result);
             break;
         default:
             break;
     }
     // http://kohanaframework.org/3.3/guide-api/Response#body
     $this->response->body($this->_result);
     parent::after();
 }