/** * Renders the view model. * * @param \Es\Mvc\ViewModelInterface $model The view model * * @return mixed The result of rendering */ public function render(ViewModelInterface $model) { foreach ($model as $child) { $groupId = $child->getGroupId(); if (empty($groupId)) { continue; } $result = $this->render($child); $oldResult = $model->getVariable($groupId, ''); $model->setVariable($groupId, $oldResult . $result); } $events = $this->getEvents(); $event = new ViewEvent($model); $events->trigger($event); return $event->getResult(); }
/** * Sets the View Model. * * @param \Es\Mvc\ViewModelInterface $model The View Model */ public function setModel(ViewModelInterface $model) { $this->model = $model->setTemplate(static::TEMPLATE); }
/** * Adds the child model. * * @param \Es\Mvc\ViewModelInterface $child The child model * @param string $groupId Optional; the group identifier * * @return self */ public function addChild(ViewModelInterface $child, $groupId = null) { $this->children[] = $child; if (!is_null($groupId)) { $child->setGroupId($groupId); } return $this; }