/** * Load a view from the current theme with the given data * * @param string $viewName * @param array $data */ public static function getView($viewName, $data = null, $templateRootFolder = null) { $view = new \erdiko\core\View($viewName, $data); if ($templateRootFolder !== null) { $view->setTemplateRootFolder($templateRootFolder); } return $view->toHtml(); }
/** * Add a view from the current theme with the given data * * @param string $viewName * @param array $data * @return string $html, view contents */ public function addView($viewName, $data = null) { $view = new \erdiko\core\View($viewName, $data); $this->appendContent($view->toHtml()); }
function testAddViewAndGetView() { $viewName = 'examples/helloworld'; /** * First Test * * Add a view without data */ $view = new \erdiko\core\View($viewName); $this->controllerObj->addView($viewName); //$return = $this->controllerObj->getResponse()->getContent(); $return = $this->controllerObj->getView($viewName); $this->assertEquals($return, $view->toHtml()); unset($this->controllerObj); $this->controllerObj = new \erdiko\core\Controller(); /** * Second Test * * Add a view with data */ $data = 'Test Data'; $view = new \erdiko\core\View($viewName, $data); $this->controllerObj->addView($viewName, $data); //$return = $this->controllerObj->getResponse()->getContent(); $return = $this->controllerObj->getView($viewName, $data); $this->assertEquals($return, $view->toHtml()); unset($this->controllerObj); $this->controllerObj = new \erdiko\core\Controller(); /** * Third Test * * Add a view, and then add another view */ //Add a view $view = new \erdiko\core\View('examples/helloworld'); $this->controllerObj->addView('examples/helloworld'); $return = $this->controllerObj->getView('examples/helloworld'); $this->assertEquals($return, $view->toHtml()); //Add another view $data = 'Test Data'; $view2 = new \erdiko\core\View('examples/carousel', $data); $this->controllerObj->addView('examples/carousel', $data); $return = $this->controllerObj->getResponse()->getContent(); $this->assertEquals($return, $view->toHtml() . $view2->toHtml()); }