Accessing element data

This short tutorial will show you how to access element data from anywhere in ZOO.

Accessing element data

In general you can get an element from an item like this:

$element = $item->getElement('ELEMENT_ID');

Now, if you don't have the item, but the item id. Do this:

$item = $this->app->table->item->get('ITEM_ID');

Now if you don't have the element id. You can always iterate over all item elements by calling:

foreach ($item->getElements() as $element) {
	do_something_with_the_element($element);
}

With the Element object, you can get and set values through its getter and setter functions.

public function get($name, $default = null);
public function set($name, $value);

If it is a repeatable element, iterate over the element itself:

foreach ($element as $self) {
	$data = $self['value'];
}

This should save some time, looking through the code!

Documentation on Github

Help us out! If you are feeling that our documentation has errors or can be improved, fork it at Github and send us a pull request. Any contribution is much appreciated. Thank you!