本帖最后由 sysmaze 于 2014-11-02 15:47:57 编辑 模板赋值问题
最终页代码如下
assign(show,'success');
$show = '111';
include('templates/index.html'); =======================这样写的话 $show能成功赋值
//include('f:/appserv/www/temp/tpl/com_index.html.php');
//$tpl->compile('index.html');===================这样写的话$show不能赋值
?>
index.html 简要代码如下 输出一个变量
问题如下:
直接在本页面下include(上面第一个代码块) include('templates/index.html'); 成功赋值可以输出$show值
简单写了个模板 核心函数 $tpl->compile('index.html'); 如下 就不能成功赋值 相对绝对路径都试过,【以下代码compile已改为绝对】,而且两个引用的路径一模一样[非绝对下]竟然不好使!!!不知道是不是涉及到global这个东西,请大神详解 ,在线等!
function compile($filename){
$ducument_root = $_server['document_root'];
$tplfile = $ducument_root.$this->template_dir.$filename; //找到模版文件
if(!file_exists($tplfile)){
return false;
}
$comfile = $ducument_root.$this->compile_dir.'com_'.basename($tplfile).'.php';//构造编译后的文件
if(!file_exists($comfile) || filemtime($comfile)tpl_replace(file_get_contents($tplfile));//获取源文件内容并替换成php源格式
$handle = fopen($comfile,'w+');
fwrite($handle,$repcontent);
fclose($handle);
}
include($comfile);
}
------解决思路----------------------
你的 kseeing::assign 方法是怎么写的?
一般的说
$tpl->assign(show,'success');
是将 'success' 赋予 $tpl 的 show 属性,通常会有一个载体
所以可能是这样 $tpl->data['show'] = 'success';
你的模板中是
所以 compile 方法中应是
extract($this->data);
include($comfile);