Added view helper functionality

pull/11/head
Mike Cao 14 years ago
parent c6df2125f6
commit fee13cf2ca

@ -8,9 +8,10 @@
*/ */
class View { class View {
public $path; public $path;
public $template;
public function __construct($path = null) { public function __construct($path = null) {
$this->path = $path ?: (Flight::get('flight.view.path') ?: './views'); $this->path = $path ?: (Flight::get('flight.views.path') ?: './views');
} }
/** /**
@ -20,17 +21,11 @@ class View {
* @param array $data Template data * @param array $data Template data
*/ */
public function render($file, $data = null) { public function render($file, $data = null) {
// Bind template data to view $this->template = (substr($file, -4) == '.php') ? $file : $file.'.php';
if (!is_null($data)) {
if (is_array($data) || is_object($data)) { extract($data);
foreach ($data as $key => $value) {
$this->{$key} = $value; include $this->path.'/'.$this->template;
}
}
}
// Display template
include $this->path.'/'.((substr($file,-4) == '.php') ? $file : $file.'.php');
} }
/** /**
@ -50,6 +45,16 @@ class View {
return $output; return $output;
} }
/**
* Loads and executes view helper functions.
*
* @param string $name Function name
* @param array $params Function parameters
*/
public function __call($name, $params) {
return Flight::invokeMethod(array('Flight', $name), $params);
}
/** /**
* Displays escaped output. * Displays escaped output.
* *

Loading…
Cancel
Save