Skip to content

Instantly share code, notes, and snippets.

@Anye
Created December 18, 2013 06:25
Show Gist options
  • Save Anye/8018087 to your computer and use it in GitHub Desktop.
Save Anye/8018087 to your computer and use it in GitHub Desktop.
simplie php template engine
<?php
/**
* 简单PHP模板引擎
*
* @author Anye
*
*/
class PHPView
{
protected $data = array();
public function __construct() { }
public function assign($varname, $var)
{
$this->data["{$varname}"] = $var;
}
public function fetch($tpl_file)
{
if (is_file($tpl_file)){
ob_start();
ob_implicit_flush(0);
$this->display($tpl_file);
$content = ob_get_clean();
return $content;
} else {
throw new Exception("{$tpl_file} NOT EXIST");
}
}
public function display($tpl_file)
{
if (is_file($tpl_file)){
extract($this->data);
include $tpl_file;
} else {
throw new Exception("{$tpl_file} NOT EXIST");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment