Created
December 18, 2013 06:25
-
-
Save Anye/8018087 to your computer and use it in GitHub Desktop.
simplie php template engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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