Smarty错误(Smarty error):unable to read resource: "s01/index.tpl" in F:\Dropbox\PHP\Smarty\Smarty.class.php on line 1093
一般出现这种问题是smarty配置问题,如:(index.php)
<?php
define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);
define('SMARTY_PATH',dirname($_SERVER['SCRIPT_NAME']));
require BASE_PATH.SMARTY_PATH.'/Smarty.class.php';
$smarty=new Smarty;
$smarty->template_dir=BASE_PATH.SMARTY_PATH.'/templates/';
$smarty->compiler_dir=BASE_PATH.SMARTY_PATH.'/templates_c/';
$smarty->config_dir=BASE_PATH.SMARTY_PATH.'/configs/';
$smarty->cache_dir=BASE_PATH.SMARTY_PATH.'/cache/';
$smarty->left_delimiter='{%';
$smarty->right_delimiter='%}';
$smarty->assign('title','我的第一个Smarty程序');
$smarty->assign('content','哈,我的第一个Smarty模板!');
$smarty->display('s01/index.tpl');
?>
但实际smarty模板文件路径是/templates/01/index.tpl,运行index.php就会报上述的错误,解决方法:
改变调用模板的路径:$smarty->display('01/index.tpl');
注意:index.php文件不包含html标签如:<title></title>,否则调用index.tpl时,定义的smarty变量$title就无法被调用,这是刚学smarty时容易忽略的问题!!
請求: /wp-comments-post.php
方式: 未經評論表格
內容: 网站新手多多关照
— 記錄成功 —