Ticket #513: view_patch.patch

File view_patch.patch, 2.2 kB (added by memon, 10 months ago)

setting view file outside of constructor

  • home/maarten/webroot/kohana_trunk/system/libraries/View.php

     
    4242         * @param   string  type of file: html, css, js, etc. 
    4343         * @return  void 
    4444         */ 
    45         public function __construct($name, $data = NULL, $type = NULL) 
     45        public function __construct($name = NULL, $data = NULL, $type = NULL) 
     46        { 
     47                if(!empty($name)) 
     48                { 
     49                        $this->set_view_file($name,$type); 
     50                } 
     51 
     52                if (is_array($data) AND ! empty($data)) 
     53                { 
     54                        // Preload data using array_merge, to allow user extensions 
     55                        $this->data = array_merge($this->data, $data); 
     56                } 
     57 
     58                Log::add('debug', 'View Class Initialized ['.$name.']'); 
     59        } 
     60         
     61        /** 
     62         * Set the view file to be used 
     63         * 
     64         * @throws  Kohana_Exception  if the requested view cannot be found 
     65         * @param       string $name 
     66         * @param   string  type of file: html, css, js, etc. 
     67         * @return  void 
     68         */ 
     69        public function set_view_file($name,$type=NULL) 
    4670        { 
    4771                if (empty($type)) 
    4872                { 
     
    5983                        // Load the filename and set the content type 
    6084                        $this->kohana_filename = Kohana::find_file('views', $name, TRUE, $type); 
    6185                        $this->kohana_filetype = Config::item('mimes.'.$type); 
    62                         $this->kohana_filetype = empty($this->kohana_filetype) ? $type : $this->kohana_filetype; 
     86                        $this->kohana_filetype = empty($this->kohana_filetype) ? $type : $this->kohana_filetype;                         
    6387                } 
    64  
    65                 if (is_array($data) AND ! empty($data)) 
    66                 { 
    67                         // Preload data using array_merge, to allow user extensions 
    68                         $this->data = array_merge($this->data, $data); 
    69                 } 
    70  
    71                 Log::add('debug', 'View Class Initialized ['.$name.']'); 
    7288        } 
    73  
     89         
    7490        /** 
    7591         * Sets a view variable. 
    7692         * 
     
    180196         */ 
    181197        public function render($print = FALSE, $renderer = FALSE) 
    182198        { 
     199                if(empty($this->kohana_filename)) 
     200                        throw new Kohana_Exception('core.view_not_set'); 
     201                         
     202                if(empty($this->kohana_filetype)) 
     203                        throw new Kohana_Exception('core.view_extension_not_set'); 
     204                 
    183205                if (is_string($this->kohana_filetype)) 
    184206                { 
    185207                        // Merge global and local data, local overrides global with the same name