Zeta Components Manual :: Docs For Class ezcTemplateVariableCollection
Template::ezcTemplateVariableCollection
Class ezcTemplateVariableCollection
Contains template variables which are sent and received from templates.
The class provides a convenient way to set and get variables as normal PHP attributes. It also works as an iterator for traverals of the variables.
NOTE: If you want to assign an array be VERY careful. Do NOT write:
- $v->myProp = array();
- $v->myProp[] = "Hello";
The next example sets and gets variables:
- $collection->character = "Londo Mollari";
- $collection->actor = "Peter Jurasik";
- $collection->race = "Centauri";
- echo "Race: " . $collection->race;
The next example shows all variables using the iterator.
- $send->red = "FF0000";
- $send->green = "00FF00";
- $send->blue = "0000FF";
- foreach ( $send as $name => $value )
- {
- echo "$name -> $value\n";
- }
Source for this file: /Template/src/variable_collection.php
Implements interfaces:
- Iterator (internal interface)
Version: | //autogen// |
Method Summary
public ezcTemplateVariableCollection |
__construct(
[ $variables
= array()] )
Initialises an empty collection of variables. |
public mixed |
current(
)
Returns the current variable |
public array(string=>mixed) |
getVariableArray(
)
Returns all variables in an array. |
public string |
key(
)
Returns the current key. |
public mixed |
next(
)
Proceed to the next element. |
public bool |
removeVariable(
$name
)
Removes the variable named $name from the collection. |
public void |
rewind(
)
Iterator rewind method |
public bool |
valid(
)
Returns true if the iterator is at a valid location. |
public mixed |
__get(
$name
)
Returns the value of the variable $name. |
public bool |
__isset(
$name
)
Returns true if the variable $name is set. |
public void |
__set(
$name
, $value
)
Sets the value in $value to the variable named $name. |
Methods
__construct
Initialises an empty collection of variables.
Note: To initialise it with existing variables pass them as the $variables parameter.
Parameters:
Name | Type | Description |
---|---|---|
$variables |
array(string=>mixed) | An array of variables to initialise the collection with. The default is an empty collection. |
current
Returns the current variable
Implementation of:
Method | Description |
---|---|
Iterator::current |
getVariableArray
Returns all variables in an array.
key
Returns the current key.
Implementation of:
Method | Description |
---|---|
Iterator::key |
next
Proceed to the next element.
Implementation of:
Method | Description |
---|---|
Iterator::next |
removeVariable
Removes the variable named $name from the collection.
If the variable doesn't exist, it returns false.
Parameters:
Name | Type | Description |
---|---|---|
$name |
string | The name of the variable to remove. |
rewind
Iterator rewind method
Implementation of:
Method | Description |
---|---|
Iterator::rewind |
valid
Returns true if the iterator is at a valid location.
Implementation of:
Method | Description |
---|---|
Iterator::valid |
__get
Returns the value of the variable $name.
Parameters:
Name | Type | Description |
---|---|---|
$name |
string |
__isset
Returns true if the variable $name is set.
Parameters:
Name | Type | Description |
---|---|---|
$name |
string |
__set
Sets the value in $value to the variable named $name.
NOTE: If you want to assign an array be VERY careful. Do NOT write:
- $v->myProp = array();
- $v->myProp[] = "Hello";
Parameters:
Name | Type | Description |
---|---|---|
$name |
string | |
$value |
mixed |