Changeset 409
- Timestamp:
- 08/26/07 13:44:14 (12 months ago)
- Location:
- branches/devel
- Files:
-
- 3 modified
-
application/controllers/welcome.php (modified) (1 diff)
-
system/libraries/Controller.php (modified) (2 diffs)
-
system/libraries/View.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel/application/controllers/welcome.php
r405 r409 1 1 <?php 2 2 3 class Welcome extends Controller {3 class Welcome_Controller extends Controller { 4 4 5 5 function index() 6 6 { 7 $this->load->view('welcome')->set('message', 'testing')->render(TRUE); 8 print "hi"; 7 print new View('welcome', array('message' => 'testing calls back to the controller')); 8 9 // $db = new Database(); 10 // print_r ($db); 9 11 } 10 12 11 function _index()13 function say_hello() 12 14 { 13 $this->load->helper('url'); 14 print "<p>Welcome to ".url::site('welcome')."!</p>\n"; 15 16 $this->load->model('users'); 17 print "<p>Model test: ".$this->users->hi()."!</p>\n"; 18 19 print "<p>Rendered in {execution_time} seconds</p>\n"; 15 return '<strong>OMG HI!!!!1</strong>'; 20 16 } 21 17 22 18 } 23 24 ?> -
branches/devel/system/libraries/Controller.php
r397 r409 2 2 3 3 class Controller_Core extends Kohana { 4 4 5 5 public function __construct() 6 6 { … … 10 10 // Loader should always be available 11 11 $this->load = new Loader(); 12 12 13 13 // URI should always be available 14 14 $this->uri = new URI(); 15 15 } 16 16 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 17 40 } // End Controller Class -
branches/devel/system/libraries/View.php
r405 r409 82 82 } 83 83 84 public function render($ kohana_display_output = FALSE, $kohana_render_function= FALSE)84 public function render($print = FALSE, $callback = FALSE) 85 85 { 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); 91 87 92 if ($ kohana_render_function != FALSE AND function_exists($kohana_render_function))88 if ($callback != FALSE) 93 89 { 94 $ kohana_view_output = $kohana_render_function($kohana_view_output);90 $output = Kohana::callback($callback, $output); 95 91 } 96 92 97 if ($ kohana_display_output == TRUE)93 if ($print == TRUE) 98 94 { 99 print $ kohana_view_output;95 print $output; 100 96 } 101 97 else 102 98 { 103 return $ kohana_view_output;99 return $output; 104 100 } 105 101 } 106 102 107 }108 109 class NOT_Core_View {110 111 var $load = '';112 var $data = array();113 var $template = 'template';114 115 /**116 * Constructor117 */118 function Core_View()119 {120 $CORE =& get_instance();121 $this->load =& $CORE->load;122 }123 124 /**125 * Get Variable126 *127 * @access public128 * @return string129 */130 function get($key)131 {132 return (isset($this->data[$key]) ? $this->data[$key] : '');133 }134 135 /**136 * Set Variable(s)137 *138 * @access public139 * @param mixed140 * @param mixed141 * @return void142 */143 function set($key, $data = FALSE)144 {145 if (is_array($key))146 {147 $this->data = array_merge($this->data, $key);148 }149 else150 {151 $this->data[$key] = $data;152 }153 }154 155 /**156 * Add to a Variable(s)157 *158 * @access public159 * @param string160 * @param string161 * @return void162 */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 else173 {174 $this->set($key, $data);175 }176 }177 178 /**179 * Delete Variables180 *181 * @access public182 * @param string183 * @return void184 */185 function del($key)186 {187 if (isset($this->data[$key]))188 {189 unset($this->data[$key]);190 }191 }192 193 /**194 * Load a View195 *196 * Loads a template for inclusion into the template, or displays the template197 *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 public209 * @param string210 * @param string211 * @return void212 */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 else232 {233 $this->load->view($view, $this->data);234 }235 }236 103 } // End View Class
