首页  >  问答  >  正文

PHP Smarty中include file问题求助急!

捕获.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}


帅帅的阿猪帅帅的阿猪2523 天前1431

全部回复(1)我来回复

  • 路过

    路过2017-10-26 08:14:36

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

    回复
    0
  • 帅帅的阿猪

    是对的,我单独访问head.php和Index.php都是正常的。

    帅帅的阿猪 · 2017-10-26 09:36:11
    路过

    回复 0:怎么算正常? 你用的$sm 实例化了吗? 就是 $sm = new Smarty();

    路过 · 2017-10-26 09:42:39
  • 取消回复