View class

Acts as an object wrapper for HTML pages with embedded PHP, called "views". Variables can be assigned with the view object and referenced locally within the view.

package Fuel
category Core
link http://docs.fuelphp.com/classes/view.html

 Methods

Sets the initial view filename and local data.

__construct(string $file, object $data, bool $filter) 

$view = new View($file);

uses \Fuel\Core\View::set_filename

Parameters

$file

string

view filename

$data

object

array of values

$filter

bool

Magic method, searches for the given variable and returns its value.

__get(string $key) : mixed

Local variables will be returned before global variables.

$value = $view->foo;

Parameters

$key

string

variable name

Exceptions

\OutOfBoundsException

Returns

mixed

Magic method, determines if a variable is set.

__isset(string $key) : boolean

isset($view->foo);

[!!] null variables are not considered to be set by isset.

Parameters

$key

string

variable name

Returns

boolean

Magic method, calls [static::set] with the same parameters.

__set(string $key, mixed $value) : void

$view->foo = 'something';

Parameters

$key

string

variable name

$value

mixed

value

Magic method, returns the output of [static::render].

__toString() : string

uses \Fuel\Core\View::render

Returns

string

Magic method, unsets a given variable.

__unset(string $key) : void

unset($view->foo);

Parameters

$key

string

variable name

Sets whether to filter the data or not.

auto_filter(bool $filter) : \Fuel\Core\View

$view->auto_filter(false);

Parameters

$filter

bool

whether to auto filter or not

Returns

Assigns a value by reference.

bind(string $key, mixed $value, bool $filter) : \Fuel\Core\View

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:

// This reference can be accessed as $ref within the view
$view->bind('ref', $bar);

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

string

variable name

$value

mixed

referenced variable

$filter

bool

Whether to filter the var on output

Returns

Assigns a global variable by reference, similar to [static::bind], except that the variable will be accessible to all views.

bind_global(string $key, mixed $value, bool $filter) : void

View::bind_global($key, $value);

Parameters

$key

string

variable name

$value

mixed

referenced variable

$filter

bool

whether to filter the data or not

Returns a new View object.

forge(string $file, object $data, bool $auto_filter) : \Fuel\Core\View

If you do not define the "file" parameter, you must call [static::set_filename].

$view = View::forge($file);

Parameters

$file

string

view filename

$data

object

array of values

$auto_filter

bool

Returns

Searches for the given variable and returns its value.

get(string $key, mixed $default) : mixed

Local variables will be returned before global variables.

$value = $view->get('foo', 'bar');

If the key is not given or null, the entire data array is returned.

If a default parameter is not given and the variable does not exist, it will throw an OutOfBoundsException.

Parameters

$key

string

The variable name

$default

mixed

The default value to return

Exceptions

\OutOfBoundsException

Returns

mixed

Renders the view object to a string.

render(\Fuel\Core\$file $file) : string

Global and local data are merged and extracted to create local variables within the view file.

$output = $view->render();

[!!] Global variables with the same key name as local variables will be overwritten by the local variable.

uses \Fuel\Core\static::capture

Parameters

$file

\Fuel\Core\$file

string view filename

Exceptions

\FuelException

Returns

string

Assigns a variable by name.

set(string $key, mixed $value, bool $filter) : \Fuel\Core\View

Assigned values will be available as a variable within the view file:

// 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'));

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

string

variable name or an array of variables

$value

mixed

value

$filter

bool

whether to filter the data or not

Returns

Sets the view filename.

set_filename(string $file, $reverse) : \Fuel\Core\View

$view->set_filename($file);

Parameters

$file

string

view filename

$reverse

Exceptions

\FuelException

Returns

Sets a global variable, similar to [static::set], except that the variable will be accessible to all views.

set_global(string $key, mixed $value, bool $filter) : void

View::set_global($name, $value);

Parameters

$key

string

variable name or an array of variables

$value

mixed

value

$filter

bool

whether to filter the data or not

The same as set(), except this defaults to not-encoding the variable on output.

set_safe(string $key, mixed $value) : \Fuel\Core\View

$view->set_safe('foo', 'bar');

fluent This method is part of a fluent interface and will return the same instance

Parameters

$key

string

variable name or an array of variables

$value

mixed

value

Returns

Retrieves all the data, both local and global.

get_data(string $scope) : array

It filters the data if necessary.

$data = $this->get_data();

Parameters

$scope

string

local/glocal/all

Returns

arrayview data

Captures the output that is generated when a view is included.

process_file(bool $file_override) : string

The view data will be extracted to make local variables.

$output = $this->process_file();

Parameters

$file_override

bool

File override

Returns

string

disable sanitation on any objects in the data that support it

unsanitize($var) : mixed

Parameters

$var

mixed

Returns

mixed

 Properties

 

<p>active language at the time the object was created</p>

$active_language : string

 

<p>active request when the View was created</p>

$active_request : \Fuel\Core\Request

 

<p>Whether to auto-filter the view's data</p>

$auto_filter : bool

 

<p>The view's data</p>

$data : array

 

<p>The view file extension</p>

$extension : string

 

<p>The view's filename</p>

$file_name : string

 

<p>Whether to filter closures</p>

$filter_closures : bool

 

<p>Global view data</p>

$global_data : array

 

<p>Holds a list of specific filter rules for global variables</p>

$global_filter : array

 

<p>Holds a list of specific filter rules for local variables</p>

$local_filter : array

 

<p>Current active search paths</p>

$request_paths : array