class MyView extends JViewLegacy { public function __construct($config = array()) { parent::__construct($config); $this->myVar = 'Hello World'; } public function display($tpl = null) { echo $this->myVar; } } $view = new MyView(); $view->display();
class MyView extends JViewLegacy { public function __construct($model = null, $config = array()) { if ($model) { $this->model = $model; } parent::__construct($config); } public function display($tpl = null) { if ($this->model) { $data = $this->model->getData(); $this->assignRef('data', $data); } parent::display($tpl); } } $model = new MyModel(); $view = new MyView($model); $view->display();In this example, the __construct method is used to set the value of a custom variable ($model) to an instance of MyModel (a custom model class). The display method then gets the data from the model and assigns it to the view's template using the assignRef method. The parent::display method is called to output the view's HTML. Package/Library: Custom Joomla component.