PHP Class Kohana_Twig, kohana-twig

Author: Jonathan Geiger
显示文件 Open project: jonathangeiger/kohana-twig Class Usage Examples

Protected Properties

Property Type Description
$_data Local data
$_environment The environment the view is attached to
$_extension The extension of the file
$_file The file to render
$_global_data Global data, merged just before compilation

Public Methods

Method Description
__construct ( $file = NULL, array $data = NULL, $env = 'default' ) Constructor
__get ( $key ) : mixed Magic method. See get()
__isset ( $key ) : boolean Magic method, determines if a variable is set and is not NULL.
__set ( $key, $value ) : void Magic method, calls set() with the same parameters.
__toString ( ) : string Magic method, returns the output of render(). If any exceptions are thrown, the exception output will be returned instead.
__unset ( $key ) : void Magic method, unsets a given variable.
as_array ( ) : array Returns the final data plus global data merged as an array
bind ( $key, &$value ) : View Assigns a value by reference. The benefit of binding is that values can be altered without re-setting them. It is also possible to bind variables before they have values. Assigned values will be available as a variable within the view file:
bind_global ( $key, &$value ) : View Assigns a global variable by reference, similar to the bind() method.
environment ( ) : Twig_Environment Returns the environment this view is attached to
extension ( ) : string Returns the template's extension
factory ( string $file = NULL, string $data = NULL, string $env = 'default' ) : void Factory for Twigs
filename ( ) : string Returns the templates filename (sans extension)
get ( $key, $default = NULL ) : mixed Searches for the given variable and returns its value.
path ( ) : string Returns the full path of the current template ($filename + $extension)
render ( $file = NULL ) : string Renders the view object to a string. Global and local data are merged and extracted to create local variables within the view file.
set ( $key, $value = NULL ) : View Assigns a variable by name. Assigned values will be available as a variable within the view file:
set_extension ( string $extension ) : void Sets a file exension
set_filename ( $file ) : View Sets the view filename.
set_global ( $key, $value = NULL ) : View Sets a global variable, similar to the set() method.

Method Details

__construct() public method

Constructor
Author: Jonathan Geiger
public __construct ( $file = NULL, array $data = NULL, $env = 'default' )
$data array

__get() public method

Magic method. See get()
public __get ( $key ) : mixed
return mixed

__isset() public method

Magic method, determines if a variable is set and is not NULL.
public __isset ( $key ) : boolean
return boolean

__set() public method

Magic method, calls set() with the same parameters.
public __set ( $key, $value ) : void
return void

__toString() public method

Magic method, returns the output of render(). If any exceptions are thrown, the exception output will be returned instead.
public __toString ( ) : string
return string

__unset() public method

Magic method, unsets a given variable.
public __unset ( $key ) : void
return void

as_array() public method

Returns the final data plus global data merged as an array
Author: Jonathan Geiger
public as_array ( ) : array
return array

bind() public method

This reference can be accessed as $ref within the view $view->bind('ref', $bar);
public bind ( $key, &$value ) : View
return View

bind_global() public static method

Assigns a global variable by reference, similar to the bind() method.
public static bind_global ( $key, &$value ) : View
return View

environment() public method

Returns the environment this view is attached to
Author: Jonathan Geiger
public environment ( ) : Twig_Environment
return Twig_Environment

extension() public method

Returns the template's extension
Author: Jonathan Geiger
public extension ( ) : string
return string

factory() public static method

Factory for Twigs
Author: Jonathan Geiger
public static factory ( string $file = NULL, string $data = NULL, string $env = 'default' ) : void
$file string
$data string
$env string
return void

filename() public method

Returns the templates filename (sans extension)
Author: Jonathan Geiger
public filename ( ) : string
return string

get() public method

Local variables will be returned before global variables.
public get ( $key, $default = NULL ) : mixed
return mixed

path() public method

Returns the full path of the current template ($filename + $extension)
Author: Jonathan Geiger
public path ( ) : string
return string

render() public method

Note: Global variables with the same key name as local variables will be overwritten by the local variable.
public render ( $file = NULL ) : string
return string

set() public method

This value can be accessed as $foo within the view $view->set('foo', 'my value'); You can also use an array to set several values at once: Create the values $food and $beverage in the view $view->set(array('food' => 'bread', 'beverage' => 'water'));
public set ( $key, $value = NULL ) : View
return View

set_extension() public method

Sets a file exension
Author: Jonathan Geiger
public set_extension ( string $extension ) : void
$extension string
return void

set_filename() public method

Sets the view filename.
public set_filename ( $file ) : View
return View

set_global() public static method

The name is a bit of a misnomer, since Twig has no real concept of "global" variables, just one context available to the entire view structure. However, it is implemented to provide an API similar to Kohana_View, as well as to allow passing a default set of values (perhaps from the 'context' configuration) that can be overridden by set(). The global data persists across environments.
public static set_global ( $key, $value = NULL ) : View
return View

Property Details

$_data protected_oe property

Local data
protected $_data

$_environment protected_oe property

The environment the view is attached to
protected $_environment

$_extension protected_oe property

The extension of the file
protected $_extension

$_file protected_oe property

The file to render
protected $_file

$_global_data protected_oe static_oe property

Global data, merged just before compilation
protected static $_global_data