求问多模板的情况下怎么第二个模板没有输出?
时间: 2015-10-21来源:开源中国
前景提要
HDC调试需求开发(15万预算),能者速来!>>>
主要代码如下:除了使用smarty调用缓存外还判断浏览器请求中的etag
if(!$smarty->isCached('departments.tpl')){ //检查etag test_etag($smarty); $sql='select * from `department` where `father` !=0'; $rs=run_sql($sql); $rs=rs_2_array($rs); $departments=json_encode($rs); $smarty->assign('departments',$departments); }else{ test_etag($smarty); } $smarty->display('departments.tpl'); function test_etag($smarty){ //检查etag,如果存在而且与当前的缓存一致,则返回304,否则返回新的etag $etag=$smarty->fetch('departments_etag.tpl'); if($etag && ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) ){ header('Etag:'.$etag,true,304); echo($_SERVER['HTTP_IF_NONE_MATCH']);BR();echo($etag); die(); } //diehere($etag); $etag=md5('common:departments:'.time().'.'.ranstr()); //diehere($etag); //$e['etag']=$etag; //$etag=$e; //$smarty->clearCache('departments_etag.tpl'); $smarty->assign('etag',$etag); header('Etag:'.$etag); //PR($etag); echo(' request:'.$_SERVER['HTTP_IF_NONE_MATCH']); echo(' now:'.$etag.' '); echo(' smarty:'); $smarty->display('departments_etag.tpl'); } 模板如下:

departments.tpl:
<{$departments}> departments_etag.tpl

<{$etag}> 但是输出的时候发现departments_etag.tpl的cache中一直没有值,调试数据如下:

request:aa556503e2c868409a0ee2cbd6cbb5ae now:fa1e596bc7bf79e8959fb7fb0bf10b1a smarty:
smarty的debug如下:
$etag Smarty_Variable Object (3)
->value = "fa1e596bc7bf79e8959fb7fb0bf10b1a"
->nocache = false
->scope = "Smarty root"
不懂了,求解

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行