Added Controller_Template clone with a default view class and template

This commit is contained in:
Dan Robertson 2010-07-14 10:43:11 +08:00 committed by Jeremy Bush
parent 706b94e9ad
commit 3f283b65d5
3 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Controller_Kostache extends Controller {
/**
* @var string page template
*/
public $template = 'template';
/**
* @var boolean auto render template
**/
public $auto_render = TRUE;
/**
* Loads the template [View] object.
*/
public function before()
{
if ($this->auto_render === TRUE)
{
// Load the template
$this->template = Walrus::factory($this->template);
}
return parent::before();
}
/**
* Assigns the template [View] as the request response.
*/
public function after()
{
if ($this->auto_render === TRUE)
{
$this->request->response = $this->template;
}
return parent::after();
}
} // End Controller_Kostache

15
classes/view/template.php Normal file
View file

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct script access.');
class View_Template extends Kostache {
/**
* @var string template title
*/
public $title = 'Brought to you by KOstache!';
/**
* @var string template content
*/
public $content = 'Hello, world!';
} // End View_Template

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{title}}</title>
</head>
<body>
<h1>{{title}}</h1>
<p>{{content}}</p>
</body>
</html>