问答详情
源自:6-1 Smarty的基本语法

做到time()的时候出问题了

报错

Notice: Undefined index: time in D:\tools\xampp\htdocs\MVC\smarty\sysplugins\smarty_internal_templatebase.php(171) : eval()'d code on line 27

Notice: Trying to get property of non-object in D:\tools\xampp\htdocs\MVC\smarty\sysplugins\smarty_internal_templatebase.php(171) : eval()'d code on line 27


这是代码test.php

<?php

require('../smarty/Smarty.class.php');

$smarty = new Smarty();

//配置

$smarty->left_delimiter="{";

$smarty->right_delimiter="}";

$smarty->template_dir="tpl";

$smarty->compile_dir="template_c";

$smarty->cache_dir="cache";


$smarty->caching=true;

$smarty->cache_lifetime=120;



$smarty->assign('time',time());

$smarty->display('test.tpl');

--------------------------------------

这是 test.tpl

{$time}

--------------------------------------

刚接触,自己解决不了了

提问者:Inoodlest 2015-04-29 14:24

个回答

  • PengCheng
    2015-04-30 09:24:03

    time() 先赋值给变量,然后再 assign