参考百度百科配置smarty出错了,菜鸟伤不起啊
下午看smarty,配置不会,有百度嘛,第一个是百科知识。
跟着配置吧。
(1) 在根目录下建立了新的目录learn/,再在learn/里建立一个目录smarty/。将刚才解压缩出来的目录的libs/拷贝到smarty/里,再在smarty/里新建templates目录,templates里新建cache/,templates/,templates_c/, config/。
(2) 新建一个模板文件:index.tpl,将此文件放在learn/smarty/templates/templates目录下,
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=gb2312">
<title>
Smarty
</title>
</head>
<body>
{#$hello#}
</body>
</html>
新建index.php,将此文件放在learn/下:
<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;//设置各个目录的路径,这里是安装的重点
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache"; //smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching = false;
$smarty->left_delimiter = "{#"; //重新定义边界,因为默认边界“{}“符,在html页面中嵌入js脚本文件编写代码段时使用的就是”{}“符,自定义边界符还可以是<{ }>, {/ /} 等
$smarty->right_delimiter = "#}";
$hello = "Hello World!";//赋值
$smarty->assign("hello",$hello);//引用模板文件
$smarty->display('index.tpl');?>
(3) 执行index.php就能看到Hello World!了。
对新手的我来说都是扯淡,等待我的是,Parse error: syntax error, unexpected T_VARIABLE in D:\wamp\www\learn\smarty\index.php on line 3
仔细看看,丫的,不会谁上传资料的时候把DOCTYPE声明没写全,应该是这样的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
可是百科上的呢<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
真是纠结啊,揣测是不是编辑的哥们最近因为csdn数据库泄漏门密码改的头晕了吧,哪怕来个注释也行啊。
丫的,气不过,不能让后人再出现那个错误了。太受打击了,编辑了次,不知道是否会提交,坐等效果。
来这成功的smarty配置成功的hello world
哦也收工,晚上看smarty手册咯。加油!