View
› Kohana_View
Class Contents
Constants
- None
Properties
- None
Class declared in SYSPATH/classes/view.php on line 3.
Methods
public __construct( )
› Kohana_View
Source Code
public function __construct($file = NULL, array $data = NULL)
{
if ($file !== NULL)
{
$this->set_filename($file);
}
if ($data !== NULL)
{
// Add the values to the current data
$this->_data = $data + $this->_data;
}
}
public __get( )
› Kohana_View
Source Code
public function & __get($key)
{
if (array_key_exists($key, $this->_data))
{
return $this->_data[$key];
}
elseif (array_key_exists($key, View::$_global_data))
{
return View::$_global_data[$key];
}
else
{
throw new Kohana_Exception('View variable is not set: :var',
array(':var' => $key));
}
}
public __isset( )
› Kohana_View
Source Code
public function __isset($key)
{
return (isset($this->_data[$key]) OR isset(View::$_global_data[$key]));
}
public __set( )
› Kohana_View
Source Code
public function __set($key, $value)
{
$this->set($key, $value);
}
public __toString( )
› Kohana_View
Source Code
public function __toString()
{
try
{
return $this->render();
}
catch (Exception $e)
{
// Display the exception message
Kohana::exception_handler($e);
return '';
}
}
public __unset( )
› Kohana_View
Source Code
public function __unset($key)
{
unset($this->_data[$key], View::$_global_data[$key]);
}
public bind( )
› Kohana_View
Source Code
public function bind($key, & $value)
{
$this->_data[$key] =& $value;
return $this;
}
public static bind_global( )
› Kohana_View
Source Code
public static function bind_global($key, & $value)
{
View::$_global_data[$key] =& $value;
}
protected static capture( )
› Kohana_View
Source Code
protected static function capture($kohana_view_filename, array $kohana_view_data)
{
// Import the view variables to local namespace
extract($kohana_view_data, EXTR_SKIP);
if (View::$_global_data)
{
// Import the global view variables to local namespace and maintain references
extract(View::$_global_data, EXTR_REFS);
}
// Capture the view output
ob_start();
try
{
// Load the view within the current scope
include $kohana_view_filename;
}
catch (Exception $e)
{
// Delete the output buffer
ob_end_clean();
// Re-throw the exception
throw $e;
}
// Get the captured output and close the buffer
return ob_get_clean();
}
public static factory( )
› Kohana_View
Source Code
public static function factory($file = NULL, array $data = NULL)
{
return new View($file, $data);
}
public render( )
› Kohana_View
Source Code
public function render($file = NULL)
{
if ($file !== NULL)
{
$this->set_filename($file);
}
if (empty($this->_file))
{
throw new Kohana_View_Exception('You must set the file to use within your view before rendering');
}
// Combine local and global data and capture the output
return View::capture($this->_file, $this->_data);
}
public set( )
› Kohana_View
Source Code
public function set($key, $value = NULL)
{
if (is_array($key))
{
foreach ($key as $name => $value)
{
$this->_data[$name] = $value;
}
}
else
{
$this->_data[$key] = $value;
}
return $this;
}
public set_filename( )
› Kohana_View
Source Code
public function set_filename($file)
{
if (($path = Kohana::find_file('views', $file)) === FALSE)
{
throw new Kohana_View_Exception('The requested view :file could not be found', array(
':file' => $file,
));
}
// Store the file path locally
$this->_file = $path;
return $this;
}
public static set_global( )
› Kohana_View
Source Code
public static function set_global($key, $value = NULL)
{
if (is_array($key))
{
foreach ($key as $key2 => $value)
{
View::$_global_data[$key2] = $value;
}
}
else
{
View::$_global_data[$key] = $value;
}
}