Heim  >  Artikel  >  Backend-Entwicklung  >  求帮助使用smarty模版时Warning: Smarty error: unable to read resource:

求帮助使用smarty模版时Warning: Smarty error: unable to read resource:

WBOY
WBOYOriginal
2016-06-23 13:34:151857Durchsuche

模板目录: 我用$tpl->template_dir查了,模板目录也没错呀,为啥显示不出来了呢,哭求帮助
错误信息:Warning: Smarty error: unable to read resource: "admin" in D:\AppServ\www\moban\libs\Smarty.class.php on line 1095
以下是初始化的程序

define(ROOT, "C:/AppServ/www/xsphp/");
include ROOT."libs/Smarty.class.php";

$tpl=new Smarty;
$tpl->template_dir=ROOT."tpl/";
$tpl->compile_dir=ROOT."com";
$tpl->left_delimiter=" $tpl->right_delimiter="}>";
主程序: require "init.inc.php";

$title="this is a title";

$content="this is body content";

$tpl->assign("title", $title);
$tpl->assign("content", $content);

$tpl->display("default/test.tpl");


回复讨论(解决方案)

没看到你display admin的代码呢?代码贴全了没?

补充一下那个主程序的代码我贴错了,应该是下面这个
require  "init.inc.php";
$title="this is a title";
$content="this is a content";
$tpl->assign("title",$title);
$tpl->assign("content",$content);
$tpl->display("admin");
echo $tpl->template_dir;
然后下面这个是admin模板里的程序:




求帮助使用smarty模版时Warning: Smarty error: unable to read resource:


没看到你display admin的代码呢?代码贴全了没?

我补充了下,您再帮我看看吧,我还是没有找出来哪里错了

$tpl->display("default/test.tpl");


default/test.tpl文件呢,创建没有。

$tpl->display("default/test.tpl");


default/test.tpl文件呢,创建没有。

创建了,上面那个贴错了,我在评论里贴了正确的,应该是$tpl->display("admin"),我创建了ammin模板

你指定你的tpl模板文件在/moban/tpl下了吗?

$tpl->display("admin"); 这个错的

define(ROOT, "C:/AppServ/www/xsphp/");
include ROOT."libs/Smarty.class.php";

$tpl=new Smarty;
$tpl->template_dir=ROOT."tpl/";
$tpl->compile_dir=ROOT."com";

你这里设置的路径就与你图片模板文件所在的路径不一致

然后
$tpl->display("admin.tpl");

然后
$tpl->display("admin.tpl");



加了后缀好使了,谢谢!
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn