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

 Methods

Sets the initial view filename and local data.

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

$view = new View($file);

uses \Fuel\Core\View::set_filename
inherited_from \Fuel\Core\View::__construct()

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
Inherited

Local variables will be returned before global variables.

$value = $view->foo;

inherited_from \Fuel\Core\View::__get()

Parameters

$key

string

variable name

Exceptions

\OutOfBoundsException

Returns

mixed

Magic method, determines if a variable is set.

__isset(string $key) : boolean
Inherited

isset($view->foo);

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

inherited_from \Fuel\Core\View::__isset()

Parameters

$key

string

variable name

Returns

boolean

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

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

$view->foo = 'something';

inherited_from \Fuel\Core\View::__set()

Parameters

$key

string

variable name

$value

mixed

value

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

__toString() : string
Inherited

uses \Fuel\Core\View::render
inherited_from \Fuel\Core\View::__toString()

Returns

string

Magic method, unsets a given variable.

__unset(string $key) : void
Inherited

unset($view->foo);

inherited_from \Fuel\Core\View::__unset()

Parameters

$key

string

variable name

_init()

_init() 

Sets whether to filter the data or not.

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

$view->auto_filter(false);

inherited_from \Fuel\Core\View::auto_filter()

Parameters

$filter

bool

whether to auto filter or not

Returns

Assigns a value by reference.

bind(string $key, mixed $value, bool $filter) : \Parser\View
Inherited

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

inherited_from \Fuel\Core\View::bind()
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
Inherited

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

inherited_from \Fuel\Core\View::bind_global()

Parameters

$key

string

variable name

$value

mixed

referenced variable

$filter

bool

whether to filter the data or not

Forges a new View object based on the extension

forge(string $file, array $data, bool $auto_encode) : object

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

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

Parameters

$file

string

view filename

$data

array

view data

$auto_encode

bool

auto encode boolean, null for default

Returns

objecta new view instance

Searches for the given variable and returns its value.

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

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.

inherited_from \Fuel\Core\View::get()

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
Inherited

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
inherited_from \Fuel\Core\View::render()

Parameters

$file

\Fuel\Core\$file

string view filename

Exceptions

\FuelException

Returns

string

Assigns a variable by name.

set(string $key, mixed $value, bool $filter) : \Parser\View
Inherited

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

inherited_from \Fuel\Core\View::set()
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
Inherited

$view->set_filename($file);

inherited_from \Fuel\Core\View::set_filename()

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
Inherited

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

inherited_from \Fuel\Core\View::set_global()

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) : \Parser\View
Inherited

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

inherited_from \Fuel\Core\View::set_safe()
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
Inherited

It filters the data if necessary.

$data = $this->get_data();

inherited_from \Fuel\Core\View::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
Inherited

The view data will be extracted to make local variables.

$output = $this->process_file();

inherited_from \Fuel\Core\View::process_file()

Parameters

$file_override

bool

File override

Returns

string

disable sanitation on any objects in the data that support it

unsanitize($var) : mixed
Inherited

inherited_from \Fuel\Core\View::unsanitize()

Parameters

$var

mixed

Returns

mixed

 Properties

 

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

$active_language : string
Inherited

inherited_from \Fuel\Core\View::$$active_language
 

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

$active_request : \Fuel\Core\Request
Inherited

inherited_from \Fuel\Core\View::$$active_request
 

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

$auto_filter : bool
Inherited

inherited_from \Fuel\Core\View::$$auto_filter
 

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

$data : array
Inherited

inherited_from \Fuel\Core\View::$$data
 

<p>The view file extension</p>

$extension : string
Inherited

inherited_from \Fuel\Core\View::$$extension
 

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

$file_name : string
Inherited

inherited_from \Fuel\Core\View::$$file_name
 

<p>Whether to filter closures</p>

$filter_closures : bool
Inherited

inherited_from \Fuel\Core\View::$$filter_closures
 

<p>Global view data</p>

$global_data : array
Inherited

inherited_from \Fuel\Core\View::$$global_data
 

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

$global_filter : array
Inherited

inherited_from \Fuel\Core\View::$$global_filter
 

<p>Holds the list of loaded files.</p>

$loaded_files : array

 

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

$local_filter : array
Inherited

inherited_from \Fuel\Core\View::$$local_filter
 

<p>Current active search paths</p>

$request_paths : array
Inherited

inherited_from \Fuel\Core\View::$$request_paths