Do not output content in "*Style::render" methods

This commit is contained in:
Dmitriy Simushev 2014-06-03 14:55:31 +00:00
parent 80f1fbbce7
commit 390391d117
6 changed files with 14 additions and 19 deletions

View File

@ -298,7 +298,8 @@ function show_install_err($text)
'errors' => array($text), 'errors' => array($text),
); );
$page_style = new \Mibew\Style\PageStyle('default'); $page_style = new \Mibew\Style\PageStyle('default');
$page_style->render('install_err', $page); start_html_output();
echo($page_style->render('install_err', $page));
exit; exit;
} }

View File

@ -395,6 +395,8 @@ $page['fixedwrap'] = true;
$page['errors'] = $errors; $page['errors'] = $errors;
$page_style = new \Mibew\Style\PageStyle('default'); $page_style = new \Mibew\Style\PageStyle('default');
$page_style->render('install_index', $page);
start_html_output();
echo($page_style->render('install_index', $page));
?> ?>

View File

@ -118,13 +118,7 @@ abstract class AbstractController implements RouterAwareInterface, Authenticatio
*/ */
public function render($template, array $parameters = array()) public function render($template, array $parameters = array())
{ {
// TODO: Remove bufferization after all pages will be replaced with return $this->getStyle()->render($template, $parameters);
// controllers and direct output will be removed from the *Style classes.
ob_start();
$this->getStyle()->render($template, $parameters);
$content = ob_get_clean();
return $content;
} }
/** /**

View File

@ -69,17 +69,16 @@ class ChatStyle extends AbstractStyle implements StyleInterface
} }
/** /**
* Renders template file to HTML and send it to the output * Renders template file to HTML.
* *
* @param string $template_name Name of the template file with neither path * @param string $template_name Name of the template file with neither path
* nor extension. * nor extension.
* @param array $data Associative array of values that should be used for * @param array $data Associative array of values that should be used for
* substitutions in a template. * substitutions in a template.
* @return string Rendered template.
*/ */
public function render($template_name, $data = array()) public function render($template_name, $data = array())
{ {
start_html_output();
// Pass additional variables to template // Pass additional variables to template
$data['mibewRoot'] = MIBEW_WEB_ROOT; $data['mibewRoot'] = MIBEW_WEB_ROOT;
$data['mibewVersion'] = MIBEW_VERSION; $data['mibewVersion'] = MIBEW_VERSION;
@ -88,7 +87,7 @@ class ChatStyle extends AbstractStyle implements StyleInterface
$data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath(); $data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath();
$data['styleName'] = $this->getName(); $data['styleName'] = $this->getName();
echo($this->templateEngine->render($template_name, $data)); return $this->templateEngine->render($template_name, $data);
} }
/** /**

View File

@ -69,18 +69,16 @@ class PageStyle extends AbstractStyle implements StyleInterface
} }
/** /**
* Renders template file to HTML and send it to the output * Renders template file to HTML.
* *
* @param string $template_name Name of the template file with neither path * @param string $template_name Name of the template file with neither path
* nor extension. * nor extension.
* @param array $data Associative array of values that should be used for * @param array $data Associative array of values that should be used for
* substitutions in a template. * substitutions in a template.
* @return string Rendered template.
*/ */
public function render($template_name, $data = array()) public function render($template_name, $data = array())
{ {
// Prepare to output html
start_html_output();
// Pass additional variables to template // Pass additional variables to template
$data['mibewRoot'] = MIBEW_WEB_ROOT; $data['mibewRoot'] = MIBEW_WEB_ROOT;
$data['mibewVersion'] = MIBEW_VERSION; $data['mibewVersion'] = MIBEW_VERSION;
@ -89,7 +87,7 @@ class PageStyle extends AbstractStyle implements StyleInterface
$data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath(); $data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath();
$data['styleName'] = $this->getName(); $data['styleName'] = $this->getName();
echo($this->templateEngine->render($template_name, $data)); return $this->templateEngine->render($template_name, $data);
} }
/** /**

View File

@ -77,12 +77,13 @@ interface StyleInterface
public function getName(); public function getName();
/** /**
* Renders template file to HTML and send it to the output * Renders template file to HTML.
* *
* @param string $template_name Name of the template file with neither path * @param string $template_name Name of the template file with neither path
* nor extension. * nor extension.
* @param array $data Associative array of values that should be used for * @param array $data Associative array of values that should be used for
* substitutions in a template. * substitutions in a template.
* @return string Rendered template.
*/ */
public function render($template_name, $data = array()); public function render($template_name, $data = array());
} }