O'Reilly logo

Zend Framework 1 to 2 Migration Guide by Bart McLeod

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The View

We already know that view scripts have improved, as you no longer need to type $this-> in front of view variables. You can use them as local variables. Let’s look at the following edge case (I have seen many views in ZF1 applications with code like this).

<?php
// variable $products instantiated in view script
$products = array('apples', 'bananas');

// $this->products assigned to view in controller action
foreach ($this->products as $product) {
   // do something
}

In ZF2, $this->products and $products are the same if products is returned in the view model, while in ZF1, they are different. However, in ZF2, as soon as we assign a new value to $products, it is different from $this->products. They are not references to each other. This is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required