Changeset 908
- Timestamp:
- 10/28/2007 04:46:51 AM (13 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/View.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/View.php
r892 r908 23 23 24 24 // The view file name and type 25 protected $kohana_filename = FALSE;26 protected $kohana_filetype = FALSE;25 protected $kohana_filename = FALSE; 26 protected $kohana_filetype = FALSE; 27 27 28 28 // Set variables 29 29 protected $data = array(); 30 30 31 /** 32 * Construct 31 /* 32 * Method: __construct 33 * 34 * Parameters: 35 * name - view filename string 36 * data - view data 33 37 */ 34 38 public function __construct($name, $data = NULL) 35 39 { 36 if (preg_match('/\.( gif|jpe?g|png|tiff?|js|css|swf)$/Di', $name, $type))40 if (preg_match('/\.(?:gif|jpe?g|png|css|js|tiff?|swf)$/Di', $name, $type)) 37 41 { 38 $type = $type[1];42 $type = substr($type[0], 1); 39 43 40 44 $this->kohana_filename = Kohana::find_file('views', $name, TRUE, $type); … … 53 57 if (is_array($data) AND ! empty($data)) 54 58 { 55 foreach($data as $ key => $val)59 foreach($data as $name => $value) 56 60 { 57 $this->data[$ key] = $val;61 $this->data[$name] = $value; 58 62 } 59 63 } … … 62 66 } 63 67 64 /** 65 * Set a variable 68 /* 69 * Method: set 70 * Sets a view variable 66 71 * 67 * @access public 68 * @param string 69 * @param mixed 70 * @return object 72 * Parameters: 73 * name - variable name 74 * value - variable contents 75 * 76 * Returns: 77 * View object 71 78 */ 72 79 public function set($name, $value) … … 76 83 } 77 84 78 /** 79 * Magic setting of a variable 85 /* 86 * Method: __set 87 * Magically sets a view variable 80 88 * 81 * @access public 82 * @param string 83 * @param mixed 84 * @return void 89 * Parameters: 90 * name - variable name 91 * value - variable contents 85 92 */ 86 93 public function __set($name, $value) … … 92 99 } 93 100 94 /** 95 * Magic getting of a variable 101 /* 102 * Method: __get 103 * Magically gets a view variable 96 104 * 97 * @access public 98 * @param string 99 * @return void 105 * Parameters: 106 * name - variable name 107 * 108 * Returns: 109 * The variable contents or NULL if the variable does not exist 100 110 */ 101 111 public function __get($name) 102 112 { 103 return empty($this->data[$name]) ? NULL : $this->data[$name];113 return isset($this->data[$name]) ? $this->data[$name] : NULL; 104 114 } 105 115 106 /** 107 * Magic object to string 116 /* 117 * Method: __toString 118 * Magically converts view object to string 108 119 * 109 * @access public 110 * @param string 111 * @param mixed 112 * @return void 120 * Returns: 121 * The rendered view 113 122 */ 114 123 public function __toString() … … 117 126 } 118 127 119 /** 120 * Render a view 128 /* 129 * Method: render 130 * Renders a view 121 131 * 122 * @access public 123 * @param string 124 * @param callback 125 * @return mixed 132 * Parameters: 133 * print - echo the output instead of returning it 134 * renderer - user defined renderer callback 135 * 136 * Returns: 137 * The rendered view if print is set to FALSE 126 138 */ 127 139 public function render($print = FALSE, $renderer = FALSE) … … 147 159 else 148 160 { 149 // Send the filetype header161 // Overwrite the content-type header 150 162 header('Content-type: '.$this->kohana_filetype); 151 163
