Zeta Components - high quality PHP components

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:

  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.  }

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

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

Implementation of:
Method Description
Iterator::current

getVariableArray

array(string=>mixed) getVariableArray( )

Returns all variables in an array.

key

string key( )

Returns the current key.

Implementation of:
Method Description
Iterator::key

next

mixed next( )

Proceed to the next element.

Implementation of:
Method Description
Iterator::next

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

Implementation of:
Method Description
Iterator::rewind

valid

bool valid( )

Returns true if the iterator is at a valid location.

Implementation of:
Method Description
Iterator::valid

__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
Documentation generated by phpDocumentor 1.4.3