刚才发错版块了,重新发一次。在php和模板使用中,前辈们建议使用smarty。于是下载了smarty,并且简单阅读了手册,觉得不够过瘾,然后又从网上找了个简单使用实例测试。实例很简单也很明了。不过在我电脑上测试无效。代码如下:
<?php
//error_reporting(E_ALL);
echo "aaaaaaaaaaa";
require 'libs/Smarty.class.php';
$tpl = new Smarty;
$tpl->template_dir = "templates/";
$tpl->compile_dir = "templates_c/";
//$tpl->config_dir = "config/";
$tpl->cache_dir = "cache/";
$tpl->left_delimiter = "<{";
$tpl->right_delimiter = "}>";
$tpl->assign("title", "this is title");
$tpl->assign("content", "this is content");
$tpl->display('test.htm');
?>html的代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
当把 $tpl = new Smarty();这一行以及后面的行注销以后,可以显示出aaaaaaaaaaaaaaaa。可是只要用$tpl = new Smarty();一实例化这个类,就会什么都不显示了。
然后我就用error_reporting(E_ALL);开启了错误报告,也是什么都没有显示。网页空空的。test.htm是在templates目录下。
libs即为smarty的目录
请问是什么原因无法实例化这个类?
<?php
//error_reporting(E_ALL);
echo "aaaaaaaaaaa";
require 'libs/Smarty.class.php';
$tpl = new Smarty;
$tpl->template_dir = "templates/";
$tpl->compile_dir = "templates_c/";
//$tpl->config_dir = "config/";
$tpl->cache_dir = "cache/";
$tpl->left_delimiter = "<{";
$tpl->right_delimiter = "}>";
$tpl->assign("title", "this is title");
$tpl->assign("content", "this is content");
$tpl->display('test.htm');
?>html的代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
当把 $tpl = new Smarty();这一行以及后面的行注销以后,可以显示出aaaaaaaaaaaaaaaa。可是只要用$tpl = new Smarty();一实例化这个类,就会什么都不显示了。
然后我就用error_reporting(E_ALL);开启了错误报告,也是什么都没有显示。网页空空的。test.htm是在templates目录下。
libs即为smarty的目录
请问是什么原因无法实例化这个类?
//error_reporting(E_ALL);
echo "aaaaaaaaaaa";
require 'libs/Smarty.class.php';
$tpl = new Smarty(); //这句你原来写错了。
$tpl->template_dir = "templates/";
$tpl->compile_dir = "templates_c/";
//$tpl->config_dir = "config/";
$tpl->cache_dir = "cache/";
$tpl->left_delimiter = "<{";
$tpl->right_delimiter = "}>";
$tpl->assign("title", "this is title");
$tpl->assign("content", "this is content");
$tpl->display('test.htm');
?>
怪了,我以前好像是用的Smarty()啊。好像也不行。怎么现在行了。
还有,smarty自带的demo里就是用的 $smarty = new Smarty;
为什么他的可以呢?我不加括号就不行?欺负人嘛
http://www.smarty.net/manual/en/api.display.php
那个demo就是下载的Smarty-2.6.26里面的一个目录demo,是一个smarty使用的例子。
那个里面没有用小括号。
候鸟这里还有个一样的贴,你也回复一下吧。把分给你。
http://topic.csdn.net/u/20100718/16/746beb99-b685-4dfe-9a36-0a28cb221c13.html?1667472597
<?phprequire 'libs/Smarty.class.php';$smarty = new Smarty;$smarty->compile_check = true;
$smarty->debugging = true;$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");
$smarty->assign("FirstName",array("John","Mary","James","Henry"));
$smarty->assign("LastName",array("Doe","Smith","Johnson","Case"));
$smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
array("I", "J", "K", "L"), array("M", "N", "O", "P")));$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));$smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX"));
$smarty->assign("option_output", array("New York","Nebraska","Kansas","Iowa","Oklahoma","Texas"));
$smarty->assign("option_selected", "NE");$smarty->display('index.tpl');?>这是他的代码。