added support for named views.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user