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/View.php

    r405 r409  
    8282        } 
    8383 
    84         public function render($kohana_display_output = FALSE, $kohana_render_function = FALSE) 
     84        public function render($print = FALSE, $callback = FALSE) 
    8585        { 
    86                 ob_start(); 
    87                 extract($this->data); 
    88                 include $this->kohana_view_filename; 
    89                 $kohana_view_output = ob_get_contents(); 
    90                 ob_end_clean(); 
     86                $output = Kohana::instance()->kohana_include_view($this->kohana_view_filename, $this->data); 
    9187 
    92                 if ($kohana_render_function != FALSE AND function_exists($kohana_render_function)) 
     88                if ($callback != FALSE) 
    9389                { 
    94                         $kohana_view_output = $kohana_render_function($kohana_view_output); 
     90                        $output = Kohana::callback($callback, $output); 
    9591                } 
    9692 
    97                 if ($kohana_display_output == TRUE) 
     93                if ($print == TRUE) 
    9894                { 
    99                         print $kohana_view_output; 
     95                        print $output; 
    10096                } 
    10197                else 
    10298                { 
    103                         return $kohana_view_output; 
     99                        return $output; 
    104100                } 
    105101        } 
    106102 
    107 } 
    108  
    109 class NOT_Core_View { 
    110  
    111         var $load     = ''; 
    112         var $data     = array(); 
    113         var $template = 'template'; 
    114  
    115         /** 
    116          * Constructor 
    117          */ 
    118         function Core_View() 
    119         { 
    120                 $CORE =& get_instance(); 
    121                 $this->load =& $CORE->load; 
    122         } 
    123  
    124         /** 
    125          * Get Variable 
    126          * 
    127          * @access      public 
    128          * @return      string 
    129          */ 
    130         function get($key) 
    131         { 
    132                 return (isset($this->data[$key]) ? $this->data[$key] : ''); 
    133         } 
    134  
    135         /** 
    136          * Set Variable(s) 
    137          * 
    138          * @access      public 
    139          * @param       mixed 
    140          * @param       mixed 
    141          * @return      void 
    142          */ 
    143         function set($key, $data = FALSE) 
    144         { 
    145                 if (is_array($key)) 
    146                 { 
    147                         $this->data = array_merge($this->data, $key); 
    148                 } 
    149                 else 
    150                 { 
    151                         $this->data[$key] = $data; 
    152                 } 
    153         } 
    154  
    155         /** 
    156          * Add to a Variable(s) 
    157          * 
    158          * @access      public 
    159          * @param       string 
    160          * @param       string 
    161          * @return      void 
    162          */ 
    163         function add($key, $data) 
    164         { 
    165                 if (! is_string($key) OR ! is_string($data)) 
    166                         return; 
    167  
    168                 if (isset($this->data[$key])) 
    169                 { 
    170                         $this->data[$key] .= $data; 
    171                 } 
    172                 else 
    173                 { 
    174                         $this->set($key, $data); 
    175                 } 
    176         } 
    177  
    178         /** 
    179          * Delete Variables 
    180          * 
    181          * @access      public 
    182          * @param       string 
    183          * @return      void 
    184          */ 
    185         function del($key) 
    186         { 
    187                 if (isset($this->data[$key])) 
    188                 { 
    189                         unset($this->data[$key]); 
    190                 } 
    191         } 
    192  
    193         /** 
    194          * Load a View 
    195          * 
    196          * Loads a template for inclusion into the template, or displays the template 
    197          * 
    198          * EXAMPLES: 
    199          * Load the "blog_content" view into the "body" variable: 
    200          *   load('blog_content', 'body') 
    201          * Load the "blog_content" view into the "blog_content" variable: 
    202          *   load('blog_content', TRUE) 
    203          * Load the currently set template and return it as a string: 
    204          *   load(TRUE) 
    205          * Load the current template and display it: 
    206          *   load() 
    207          * 
    208          * @access      public 
    209          * @param       string 
    210          * @param       string 
    211          * @return      void 
    212          */ 
    213         function load($view = FALSE, $partial = FALSE) 
    214         { 
    215                 if ($view == FALSE) 
    216                 { 
    217                         $view = $this->template; 
    218                 } 
    219                 elseif ($view === TRUE) 
    220                 { 
    221                         return $this->load->view($this->template, $this->data, TRUE); 
    222                 } 
    223  
    224                 if ($partial != FALSE) 
    225                 { 
    226                         $key = ($partial === TRUE) ? $view : $partial; 
    227                         $this->data[$key] = $this->load->view($view, $this->data, TRUE); 
    228  
    229                         return $this->data[$key]; 
    230                 } 
    231                 else 
    232                 { 
    233                         $this->load->view($view, $this->data); 
    234                 } 
    235         } 
    236103} // End View Class