wikipoints/ground/classes/controller.php

70 lines
1.4 KiB
PHP

<?php
abstract class Controller
{
static $layout = 'layout.php';
static private $styles = array();
static private $scripts = array();
static function addStyle($name)
{
if (array_search($name, self::$styles) === FALSE )
{
self::$styles[] = $name;
}
}
static function addScript($name)
{
if (array_search($name, self::$scripts) === FALSE )
{
self::$scripts[] = $name;
}
}
static function renderPartial($template, $data, $return = false)
{
if (!file_exists(App::getBasedir() . 'views/' . $template))
return 'Template not found';
if ($return)
$oldContentFormBuffer_temp = ob_get_clean();
extract($data);
include App::getBasedir() . 'views/' . $template;
if ($return)
{
$newContentFormBuffer_temp = ob_get_clean();
echo $oldContentFormBuffer_temp;
return $newContentFormBuffer_temp;
} else
{
echo $newContentFormBuffer_temp;
}
}
static function render($template, $data, $return = false)
{
$content = self::renderPartial($template, $data, true);
$result = self::renderPartial(self::$layout, array(
'content' => $content,
'styles' => self::$styles,
'scripts' => self::$scripts,
), true);
if ($return)
{
return $result;
} else
{
echo $result;
}
}
}