Skip to content

Instantly share code, notes, and snippets.

@Anye

Anye/PHPView.php

Created Dec 18, 2013
Embed
What would you like to do?
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
You can’t perform that action at this time.