search

Home  >  Q&A  >  body text

Urgent help on include file problem in PHP Smarty!

捕获.JPG

The picture is my site directory, index.php is in the root directory, head.php and the instantiated smarty class file (config.php) are in the include directory, and templates store index Directory of .html and head.html files.

I would like to ask why I instantiated classes in index.php and head.php respectively, then assigned an attribute, displayed the corresponding html file, and then used {include file= in index.html 'head.html'} shows that the variable I gave in head.php does not exist? Access index.php and head.php respectively. Normal

post code:

index.php file

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

index.html file

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

head.php File

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

head.htmlFile

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


帅帅的阿猪帅帅的阿猪2576 days ago1476

reply all(1)I'll reply

  • 路过

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

    Have a look at the path of the imported file in head.php, is that correct?

    reply
    0
  • 帅帅的阿猪

    That's right, it's normal for me to access head.php and Index.php separately.

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

    Reply 0: How is it considered normal? Have you instantiated the $sm you used? That is $sm = new Smarty();

    路过 · 2017-10-26 09:42:39
  • Cancelreply