Advertisement
Guest User

Untitled

a guest
Jul 20th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3.  * Controller for automatic templating
  4.  */
  5. class Controller extends Kohana_Controller {
  6.  
  7.     public $view = 'layout';
  8.     protected $load_UI = FALSE;
  9.     public $auto_render = TRUE;
  10.  
  11.     /**
  12.      * Loads the view [View] object.
  13.      */
  14.     public function before()
  15.     {
  16.         parent::before();
  17.  
  18.         $this->request->headers('X-Powered-By', 'Kohana '.Kohana::VERSION);
  19.                
  20.         if ($this->auto_render === TRUE)
  21.         {
  22.             $this->view = View::factory($this->view);
  23.         }
  24.                
  25.     }
  26.  
  27.     /**
  28.      * Assigns the view [View] as the request response.
  29.      */
  30.     public function after()
  31.     {
  32.        
  33.         // If HTML is supposed to be rendered and response body hasn't been set
  34.         if ($this->auto_render AND ! $this->response->body())
  35.         {
  36.             // If AJAX or sub-request - render the content only, otherwise the whole view
  37.             if ( ! $this->request->is_initial() OR $this->request->is_ajax())
  38.             {
  39.                 $this->response->body($this->view->content);
  40.             }
  41.             // .. or save resources if view isn't being rendered
  42.             else
  43.             {
  44.                 // Finally, render the view and respond
  45.                 $this->response->body($this->view);
  46.             }
  47.         }
  48.  
  49.         return parent::after();
  50.     }
  51.  
  52. } // End Controller_view
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement