Commit c1ca97d9 authored by Taylor Otwell's avatar Taylor Otwell

added support for named views.

parent 198e9591
<?php
return array(
/*
|--------------------------------------------------------------------------
| Named Views
|--------------------------------------------------------------------------
|
| Here you can define all of the named views for your application.
|
| Once you have defined the named view, you can create a View instance for
| that view using the View::of dynamic static method.
|
| For example, if you define a named view named "layout", you could create
| an instance of that View by calling: View::of_layout().
|
| For more info, check out: http://laravel.com/docs/start/views#named
|
| Note: The view path should be relative to the application/view directory.
|
*/
'names' => array(
'home' => 'home/index',
),
);
\ No newline at end of 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)
{
......
......@@ -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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment