It is a PHP template library which means that the code in the templates is in PHP rather than
another pseudo-language like Smarty for instance. However, it is easy to extend Zend_View to support any
other template system.
Assigning data to the view
In order for the view to display data from the model, it is necessary to assign it. Zend_View??™s assign() method
allows for assigning simple variables using $view->assign('title', 'Hello World!'); or you
can assign multiple variables simultaneously using an associative array:
$music = array('title'=>'Abbey Road', 'artist'=>'The Beatles');
$music = array('title'=>'The Wall', 'artist'=>'Pink Floyd');
$view->assign($music);
As we are using PHP5, we can also take advantage of the __set()magic method to write $view->title
= 'Hello World!'; and it will work exactly the same way and the data from the model or controller
is now available to the view template.
The view template
A view template is just like any other regular PHP file, except that its scope is contained within an instance of
a Zend_View object. This means that it has access to all the methods and data of Zend_View as if it was a
function within the class. The data that we assigned to the view are public properties of the view class and so
Licensed to Menshu You
Pages:
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67