Path

ez components / documentation / api reference / 2009.1.1 / template


eZ Components 2009.1.1

Template: ezcTemplateVariableCollection

[ Tutorial ] [ EBNF ] [ Functions ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcTemplateVariableCollection

Contains template variables which are sent and received from templates. [source]

Implemented Interfaces

  • Iterator (internal interface)

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:
1.  $v->myProp array();
2.  $v->myProp["Hello";
Because 'myProp' will still be an empty array. (Stupid PHP)
The next example sets and gets variables:
1.  $collection new ezcTemplateVariableCollection();
2.  $collection->character "Londo Mollari";
3.  $collection->actor "Peter Jurasik";
4.  $collection->race "Centauri";
5.  
6.  echo "Race: " $collection->race;
The next example shows all variables using the iterator.
 1.  $send new ezcTemplateVariableCollection();
 2.  
 3.  $send->red "FF0000";
 4.  $send->green "00FF00";
 5.  $send->blue "0000FF";
 6.  
 7.  foreach $send as $name => $value )
 8.  {
 9.      echo "$name  -> $value\n";
10.  }

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

ezcTemplateVariableCollection __construct( [array(string=>mixed) $variables = array()] )
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

mixed current( )
Returns the current variable

getVariableArray

array(string=>mixed) getVariableArray( )
Returns all variables in an array.

key

string key( )
Returns the current key.

next

mixed next( )
Proceed to the next element.

removeVariable

bool removeVariable( string $name )
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

void rewind( )
Iterator rewind method

valid

bool valid( )
Returns true if the iterator is at a valid location.

__get

mixed __get( string $name )
Returns the value of the variable $name.

Parameters

Name Type Description
$name string  

__isset

bool __isset( string $name )
Returns true if the variable $name is set.

Parameters

Name Type Description
$name string  

__set

void __set( string $name, mixed $value )
Sets the value in $value to the variable named $name.
NOTE: If you want to assign an array be VERY careful. Do NOT write:
1.  $v->myProp array();
2.  $v->myProp["Hello";
Because 'myProp' will still be an empty array. (Stupid PHP)

Parameters

Name Type Description
$name string  
$value mixed  

Last updated: Mon, 27 Jul 2009