Working with Addons/Modules/Views

Usage of views

View class

Each view object that we develop inherits from the view object provided by the framework. This parent class is found at framework/kernel/view.class.php

Let's examine each of this object methods and see how we can use them.

string config(string $item [, string $section])

Returns the same value that would be returned by the parent addon config() method.
Each view has access to the parent addon config file as if the file was defined for the view.

See addon's config() method.

mixed get_value(string $val_name)

Returns the value assigned to the $val_name attribute of the view object.

$view = $this->load_view('my_view', array('name' => 'John')); $name = $this->view->get_value('name');

will assign 'John' to $name

string id_addon()

Returns the name of the view's parent addon.

string language(string $item [, string value1 ][, string $valueN])

Returns the language translation value for key $item.
Each view has access to the same language translation files as its parent addon.

See addon's language() method.

See also: language management.

void reset()

Resets the value of all the view attributes

string run()

Renders the view and returns the generated content.

$view = $this->load_view('my_view'); $buffer = $view->run();

void set_value(mixed $val_name [, string $value = NULL])

If the method is called with two arguments, the first one is a string giving the name of the view attribute that should be set to the value provided by the second argument.

When called with a single argument, the argument must be an array whose keys are taken as the name of the view attributes that should be set to the corresponding value.

$arr = array('name' => 'John', 'surname' => 'Smith'); $view = $load_view('my_view'); $view->set_value($arr);

is equivalent to:

$view = $load_view('my_view'); $view->name = 'John'; $view->surname = 'Smith';


$view = $load_view('my_view'); $view->set_value('name' , 'John'); $view->set_value('surname' , 'Smith');