smarty在模板中使用保留变量报错。

smarty在模板中使用保留变量报错。

在模板上使用$smarty.get.name报错,使用$smarty.const.name也报错

相关代码

1.demo.php

<?php
require './Smarty/Smarty.class.php';
$smarty = new Smarty();
define('age','22');
$smarty->display('1-demo.html');

1.demo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{$smarty.get.name}
{$smarty.const.age}
</body>
</html>

游览器:localhost/smarty03/1-demo.php?name=tom

PHP报错:

Notice: Undefined index: smarty in /Users/macbook/Documents/PHP-student/smarty03/templates_c/e0e1c95d98e68dc7c3d00c8feb2a0e652ad89221_0.file.1-demo.html.php on line 31

Notice: Trying to get property 'value' of non-object in /Users/macbook/Documents/PHP-student/smarty03/templates_c/e0e1c95d98e68dc7c3d00c8feb2a0e652ad89221_0.file.1-demo.html.php on line 31

Notice: Undefined index: smarty in /Users/macbook/Documents/PHP-student/smarty03/templates_c/e0e1c95d98e68dc7c3d00c8feb2a0e652ad89221_0.file.1-demo.html.php on line 33

Notice: Trying to get property 'value' of non-object in /Users/macbook/Documents/PHP-student/smarty03/templates_c/e0e1c95d98e68dc7c3d00c8feb2a0e652ad89221_0.file.1-demo.html.php on line 33
阅读 1.7k
1 个回答

原来是自己下载的文件有问题,重新在官网下最新版解决了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题