smarty模板 template_c报错,传参就没问题,不传参就会报错
publicfunctionindex(){$arr=array("title"=>"测试用的网页标题","content"=>"测试用的网页内容");//self::d...
public function index() {
$arr = array("title"=>"测试用的网页标题", "content"=>"测试用的网页内容");
// self::display($arr);
self::display();
}
public function display($arr = array(),$cache = true){
//smarty目录
define('MY_SMARTY_DIR',$_SERVER['DOCUMENT_ROOT'].'/libs');
//缓存目录
define('MY_SMARTY_CACHE_DIR',MY_SMARTY_DIR.'/cache');
$str = explode("/", $_SERVER['PATH_INFO']);
//模板文件存放的目录
$dir = $_SERVER['DOCUMENT_ROOT'].'/application/'.$str[1].'/View/'.$str[2];
//编译目录
define('MY_SMARTY_COMPILE_DIR',MY_SMARTY_DIR.'/templates_c');
require_once MY_SMARTY_DIR.'/smarty.class.php';
$smarty=new Smarty();
$smarty->setTemplateDir($dir)
//编译后的存放目录
->setCompileDir(MY_SMARTY_COMPILE_DIR)
// 缓存文件存放目录
->setCacheDir(MY_SMARTY_CACHE_DIR);
// 缓存开关
$smarty->caching=$cache;
// 设置模板配置文件存放目录
// $smarty->setConfigDir("../configs/");
// debug
$smarty->debugging = false;
// 缓存有效时间段
// $Smarty->cache_lifetime=60*60*24;
// 设置时区
date_default_timezone_set('Asia/Shanghai'); //设置时区
$smarty->left_delimiter="{";
$smarty->right_delimiter="}";
if(count($arr)){
foreach ($arr as $key => $value) {
$smarty->assign($key,$value);
}
}
$smarty->display($dir.'/'.$str[3].'.html');
}
如果$arr为空,就会报错?这是为什么?
templates_c下没有文件
报错:
Notice: Undefined index: title in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 25
Notice: Trying to get property of non-object in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 25
Notice: Undefined index: content in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 28
Notice: Trying to get property of non-object in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 28 展开
$arr = array("title"=>"测试用的网页标题", "content"=>"测试用的网页内容");
// self::display($arr);
self::display();
}
public function display($arr = array(),$cache = true){
//smarty目录
define('MY_SMARTY_DIR',$_SERVER['DOCUMENT_ROOT'].'/libs');
//缓存目录
define('MY_SMARTY_CACHE_DIR',MY_SMARTY_DIR.'/cache');
$str = explode("/", $_SERVER['PATH_INFO']);
//模板文件存放的目录
$dir = $_SERVER['DOCUMENT_ROOT'].'/application/'.$str[1].'/View/'.$str[2];
//编译目录
define('MY_SMARTY_COMPILE_DIR',MY_SMARTY_DIR.'/templates_c');
require_once MY_SMARTY_DIR.'/smarty.class.php';
$smarty=new Smarty();
$smarty->setTemplateDir($dir)
//编译后的存放目录
->setCompileDir(MY_SMARTY_COMPILE_DIR)
// 缓存文件存放目录
->setCacheDir(MY_SMARTY_CACHE_DIR);
// 缓存开关
$smarty->caching=$cache;
// 设置模板配置文件存放目录
// $smarty->setConfigDir("../configs/");
// debug
$smarty->debugging = false;
// 缓存有效时间段
// $Smarty->cache_lifetime=60*60*24;
// 设置时区
date_default_timezone_set('Asia/Shanghai'); //设置时区
$smarty->left_delimiter="{";
$smarty->right_delimiter="}";
if(count($arr)){
foreach ($arr as $key => $value) {
$smarty->assign($key,$value);
}
}
$smarty->display($dir.'/'.$str[3].'.html');
}
如果$arr为空,就会报错?这是为什么?
templates_c下没有文件
报错:
Notice: Undefined index: title in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 25
Notice: Trying to get property of non-object in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 25
Notice: Undefined index: content in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 28
Notice: Trying to get property of non-object in F:\www\imekoo\libs\templates_c\757f36df10d38f8ed3f7194160e6704f6de57e56_0.file.index.html.cache.php on line 28 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询