All view classes extend the abstract JView class. This example shows a very basic
implementation of the MyextensionViewFoobar class:
// ensure a valid entry point
defined(_JEXEC) or die('Restricted Access');
// import the JView class
jimport('joomla.application.component.view');
/**
* Foobar View
*/
class MyextensionViewFoobar extends JView
{ }
Note that when we build a view we must import the joomla.application.
component.view library. This guarantees that the JView class is present.
The most important method in any view class is the display() method; this method
is already defined in the parent class JView. The display() method is where all of
the workings take place. We interrogate models for data, customize the document,
and render the view.
We never modify data from within the view. Data is only to be
modified in the model and controller.
Component Design
[ 76 ]
Let us continue modifying our previous example; we will display a Foobar. To
do this we need to override the display() method, get the necessary data from a
MyextensionModelFoobar object and render it:
/**
* Foobar View
*/
class MyextensionViewFoobar extends JView
{
/**
* Renders the view
*
*/
function display()
{
// interrogate the model
$foobar =& $this->get('Foobar');
$this->assignRef('foobar', $foobar);
// display the view
parent::display();
}
}
There is not a big difference here; all we have done is overridden the display method
and interrogated the model.
Pages:
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113