这是tpl文件中用来显示GUI的东西。我都贴出来了。此代码如何读取tpl文件并显示HTML显示。执行此操作的是哪个命令。
class Template {
/**
* Config
*
* @access private
*/
private static $config;
/**
* Path templates
*
* @access private
*/
private $tpl_path = null;
/**
* Values
*
* @access private
*/
private $values = array();
/**
* Constructor
*
* @access public
*/
public function __construct($tpl_path) {
self::$config = config_load('template');
$this->tpl_path = $tpl_path;
}
/**
* Set a template variable
*
* @access public
*/
public function set($name, $value = null) {
if(is_array($name)) {
foreach ($name as $key => $value) {
$this->values[$key] = $value;
}
} else {
$this->values[$name] = $value;
}
}
/**
* Display the template file
*
* @access public
*/
public function display($template) {
if ($this->values) {
extract($this->values);
}
if (file_exists($this->tpl_path . $template . self::$config['template_extension'])) {
ob_start();
include($this->tpl_path . $template . self::$config['template_extension']);
$output = ob_get_contents();
ob_end_clean();
} else {
die('Template file '. $this->tpl_path . $template . self::$config['template_extension'] . ' not found.');
}
if ($output) echo $output;
}
}
?>我有一个使用这个类的文件,代码是
$tpl->set('customer_details', $customer_details);
$tpl->set('customer_addresses', $customer_addresses);
$tpl->set('countries', $countries);
//Display the template
$tpl->display('edit_account');上面的代码使用了tpl和设置值。而是如何设置和显示这些值
发布于 2017-01-28 03:21:52
这很简单。类代码使用php include。这些模板可以像任何php文件一样自由地混合php和HTML,并且可以插入变量。该类使用输出缓冲来存储输出,然后使用echo返回输出。类中使用的变量通常使用set方法提供,该方法将所有变量放入名为“values”的类数组变量中,该变量在模板文件中无疑会被引用。
https://stackoverflow.com/questions/41901302
复制相似问题