PHP Smarty中include file问题求助急!
帅帅的阿猪
帅帅的阿猪 2017-10-25 20:18:35
0
1
1453

捕获.JPG

图片是我的站点目录,index.php在根目录下,head.php和实例化smarty类文件(config.php)在include目录下,templates是存放index.html和head.html文件的目录。

想问一下为什么我分别在index.php和head.php里面实例化了类,然后assign了一个属性,display了对应的html文件,然后在index.html里面使用{include file='head.html'}显示不存在我在head.php里面给的变量?分别访问index.php与head.php正常

帖代码:

index.php文件

<?php
require_once 'include/config.php';
$sm->assign('title','hello');
$sm->display('templates/index.html');
?>

index.html文件

{include file='head.html'}
{$title}
</body>
</html>

head.php文件

<?php
require_once 'config.php';
$sm->assign('hea','这是head头部');
$sm->display(FILES.'templates/head.html');
?>

head.html文件

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
{$hea}


帅帅的阿猪
帅帅的阿猪

我是一只帅帅的阿猪

全部回复(1)
路过

你看看head.php里面引入文件的路径对吗?

  • 回复 是对的,我单独访问head.php和Index.php都是正常的。
    帅帅的阿猪 作者 2017-10-26 09:36:11
  • 回复 回复 0:怎么算正常? 你用的$sm 实例化了吗? 就是 $sm = new Smarty();
    路过 作者 2017-10-26 09:42:39
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!