added support for named views.

This commit is contained in:
Taylor Otwell
2011-07-21 23:30:52 -05:00
parent 198e95910d
commit c1ca97d9fb
3 changed files with 59 additions and 5 deletions

View File

@@ -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)
{

View File

@@ -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.
*/