From fee13cf2ca1b91e3998700859e842925a4ac48fc Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 9 May 2011 15:59:47 -0700 Subject: [PATCH] Added view helper functionality --- flight/View.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/flight/View.php b/flight/View.php index 3def506..b10be08 100644 --- a/flight/View.php +++ b/flight/View.php @@ -8,9 +8,10 @@ */ class View { public $path; + public $template; 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 */ public function render($file, $data = null) { - // Bind template data to view - if (!is_null($data)) { - if (is_array($data) || is_object($data)) { - foreach ($data as $key => $value) { - $this->{$key} = $value; - } - } - } - - // Display template - include $this->path.'/'.((substr($file,-4) == '.php') ? $file : $file.'.php'); + $this->template = (substr($file, -4) == '.php') ? $file : $file.'.php'; + + extract($data); + + include $this->path.'/'.$this->template; } /** @@ -50,6 +45,16 @@ class View { 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. *