diff --git a/application/config/view.php b/application/config/view.php new file mode 100644 index 00000000..b598cbe5 --- /dev/null +++ b/application/config/view.php @@ -0,0 +1,30 @@ + array( + + 'home' => 'home/index', + + ), + +); \ No newline at end of file diff --git a/system/redirect.php b/system/redirect.php index df3eb094..1c90c789 100644 --- a/system/redirect.php +++ b/system/redirect.php @@ -27,7 +27,7 @@ class Redirect { * @param string $method * @param int $status * @param bool $https - * @return Response + * @return Redirect */ public static function to($url, $method = 'location', $status = 302, $https = false) { diff --git a/system/view.php b/system/view.php index 6a5b5012..40b64467 100644 --- a/system/view.php +++ b/system/view.php @@ -16,6 +16,13 @@ class View { */ public $data = array(); + /** + * The path to the view. + * + * @var string + */ + public $path; + /** * Create a new view instance. * @@ -27,6 +34,7 @@ class View { { $this->view = $view; $this->data = $data; + $this->path = $this->find(); } /** @@ -38,7 +46,7 @@ class View { */ public static function make($view, $data = array()) { - return new self($view, $data); + return new static($view, $data); } /** @@ -61,9 +69,7 @@ class View { ob_start(); - $path = $this->find(); - - try { include $path; } catch (\Exception $e) { Error::handle($e); } + try { include $this->path; } catch (\Exception $e) { Error::handle($e); } return ob_get_clean(); } @@ -105,6 +111,24 @@ class View { return $this; } + /** + * Magic Method for creating named view instances. + */ + public static function __callStatic($method, $parameters) + { + if (strpos($method, 'of_') === 0) + { + $views = Config::get('view.names'); + + if ( ! array_key_exists($view = substr($method, 3), $views)) + { + throw new \Exception("Named view [$view] is not defined."); + } + + return static::make($views[$view], (isset($parameters[0]) and is_array($parameters[0])) ? $parameters[0] : array()); + } + } + /** * Magic Method for getting items from the view data. */