I have been reading an article for many times and yet, I can't still understand some parts. Link for the article : Model-View-Confusion part 1: Why the model is accessed by the view in MVC
The code below is the one I think I am confused on.
class ListView extends View {
public $model;
public $template;
public $listTemplate;
public $errorTemplate;
public $itemName = 'items';
public function output() {
$result = $this->model->findAll();
if (count($result) > 0) {
$this->template = $this->getTemplate($this->listTemplate);
$this->template->addSet($this->itemName, $result);
} else {
$this->template = $this->getTemplate($this->errorTemplate);
}
return $this->template->render();
}
}
And the controller looks like this :
class UserController extends Controller {
public $viewName = 'ListView';
public function showList() {
$this->view->model = $this->model->user;
$this->view->listTemplate = 'UserList.tpl';
$this->view->errorTemplate = 'ErrorNoUsers.tpl';
}
}
As I can understand the template
was assigned to a result of a method inherited from the View
named getTemplate
passed with a method from the View
again named listTemplate
like this $this->getTemplate($this->listTemplate)
What I am confused on is that the $template
suddenly had a method, which means it becomes a class . right here $this->template->addSet($this->itemName, $result);
and `$this->template->render();
Do you have any idea what happened right there?