46 lines
850 B
PHP
46 lines
850 B
PHP
<?php
|
|
|
|
abstract class Controller
|
|
{
|
|
|
|
static $layout = 'layout.php';
|
|
|
|
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), true);
|
|
|
|
if ($return)
|
|
{
|
|
return $result;
|
|
} else
|
|
{
|
|
echo $result;
|
|
}
|
|
}
|
|
|
|
}
|