Changeset 1434

Show
Ignore:
Timestamp:
12/06/2007 04:45:58 PM (13 months ago)
Author:
PugFish
Message:

Added set_global() to View

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/View.php

    r1410 r1434  
    1919        // Set variables 
    2020        protected $data = array(); 
     21        protected static $global_data = array(); 
    2122 
    2223        /** 
     
    7980 
    8081        /** 
     82         * Sets a view global variable. 
     83         * 
     84         * @param   string|array  name of variable or an array of variables 
     85         * @param   value         value when using a named variable 
     86         * @return  object 
     87         */ 
     88        public function set_global($name, $value = NULL) 
     89        { 
     90                if ( ! is_array($name)) 
     91                { 
     92                        $name = array($name => $value); 
     93                } 
     94 
     95                foreach ($name as $key => $value) 
     96                { 
     97                        self::$global_data[$key] = $value; 
     98                } 
     99 
     100                return $this; 
     101        } 
     102 
     103        /** 
    81104         * Magically sets a view variable. 
    82105         * 
     
    130153                if ($this->kohana_filetype === EXT) 
    131154                { 
     155                        // Merge global and local data, local overrides global with the same name 
     156                        $data = array_merge(self::$global_data, $this->data); 
     157 
    132158                        // Load the view in the controller for access to $this 
    133                         $output = Kohana::instance()->_kohana_load_view($this->kohana_filename, $this->data); 
     159                        $output = Kohana::instance()->_kohana_load_view($this->kohana_filename, $data); 
    134160 
    135161                        if ($renderer == TRUE AND is_callable($renderer, TRUE))