Commit f4f82d17 by Taylor Otwell

Added View::of method and $view->partial() method.

parent 989ba674
...@@ -50,6 +50,25 @@ class View { ...@@ -50,6 +50,25 @@ class View {
} }
/** /**
* Create a new named view instance.
*
* @param string $view
* @param array $data
* @return View
*/
public static function of($view, $data = array())
{
$views = Config::get('view.names');
if ( ! array_key_exists($view, $views))
{
throw new \Exception("Named view [$view] is not defined.");
}
return static::make($views[$view], $data);
}
/**
* Get the parsed content of the view. * Get the parsed content of the view.
* *
* @return string * @return string
...@@ -99,6 +118,19 @@ class View { ...@@ -99,6 +118,19 @@ class View {
} }
/** /**
* Add a view instance to the view data.
*
* @param string $key
* @param string $view
* @param array $data
* @return View
*/
public function partial($key, $view, $data = array())
{
return $this->bind($key, View::make($view, $data));
}
/**
* Add a key / value pair to the view data. * Add a key / value pair to the view data.
* *
* @param string $key * @param string $key
...@@ -118,14 +150,7 @@ class View { ...@@ -118,14 +150,7 @@ class View {
{ {
if (strpos($method, 'of_') === 0) if (strpos($method, 'of_') === 0)
{ {
$views = Config::get('view.names'); return static::of(substr($method, 3), Arr::get($parameters, 0, array()));
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());
} }
} }
......
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