Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Assigning Variables

Your controller script should assign necessary variables to the view before it hands over control to the view script. Normally, you can do assignments one at a time by assigning to property names of the view instance:

= new Zend_View();

However, this can be tedious when you have already collected the values to be assigned into an array or object.

The assign() method lets you assign from an array or object "in bulk". The following examples have the same effect as the above one-by-one property assignments.

= new Zend_View();

// assign an array of key-value pairs, where the
// key is the variable name, and the value is
// the assigned value.
$array = array(
'a' => "Hay",
'b' => "Bee",
'c' => "Sea",

// do the same with an object's public properties;
// note how we cast it to an array when assigning.
$obj = new StdClass;
$view->assign((array) $obj);

Alternatively, you can use the assign method to assign one-by-one by passing a string variable name, and then the variable value.

= new Zend_View();

Zend Framework