Show
Ignore:
Timestamp:
08/26/2007 01:44:14 PM (16 months ago)
Author:
Shadowhand
Message:

Fixing View to allow $this to be used in views (and refer to the controller), and enabling view-in-view loading to work. Also updated the Welcome controller to demonstrate how it's done.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/devel/system/libraries/Controller.php

    r397 r409  
    22 
    33class Controller_Core extends Kohana { 
    4          
     4 
    55        public function __construct() 
    66        { 
     
    1010                // Loader should always be available 
    1111                $this->load = new Loader(); 
    12                  
     12 
    1313                // URI should always be available 
    1414                $this->uri = new URI(); 
    1515        } 
    1616 
     17        public function kohana_include_view($kohana_view_filename, $kohana_input_data) 
     18        { 
     19                // Buffering on 
     20                ob_start(); 
     21 
     22                // Import the input variables to local namespace 
     23                extract($kohana_input_data, EXTR_SKIP); 
     24 
     25                // Views are straight HTML pages with embedded PHP, so importing them 
     26                // this way insures that $this can be accessed as if the user was in 
     27                // the controller, which gives the easiest access to libraries in views 
     28                include $kohana_view_filename; 
     29 
     30                // Fetch the HTML output 
     31                $kohana_view_output = ob_get_contents(); 
     32 
     33                // Flush the buffer 
     34                ob_end_clean(); 
     35 
     36                // Return the view, yay! 
     37                return $kohana_view_output; 
     38        } 
     39 
    1740} // End Controller Class