Example #1
0
 /**
  * Method automatically invoked after the current Action, when it not return a
  * null or boolean value. This Method is supposed to be overriden for using it.
  *
  * Note that the Action's returned value is passed to this Method as parameter.
  */
 protected function after($data)
 {
     if (is_string($data)) {
         // The data is a String; send the Response Headers and output it.
         Response::sendHeaders();
         echo $data;
     } else {
         if (is_array($data)) {
             // The data is an Array; prepare and send a JSON response.
             header('Content-Type: application/json', true);
             echo json_encode($data);
         } else {
             if (!$data instanceof View) {
                 // The data is not a View instance; no further processing required.
                 return;
             }
         }
     }
     //
     // Execute the default Template-based rendering of the given View instance.
     if (!$data instanceof Template && $this->layout !== false) {
         // The View instance is NOT a Template, but we have a Layout specified.
         Template::make($this->layout, array(), $this->template)->withContent($data)->display();
     } else {
         // The given View instance is a Template, or no Layout is specified.
         $data->display();
     }
 }