免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4251 | 回复: 1
打印 上一主题 下一主题

尝试用smarty2.6.28结果没搞出效果来 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-05-07 15:45 |只看该作者 |倒序浏览
本帖最后由 yum2014 于 2014-05-07 15:48 编辑

win7 64位+wamp.
php版本是5.3.

smarty2.6解压后。libs目录改名为smarty文件夹。复制到www下的news目录下。

建立了一个smarty.php文件内容是
  1. <?
  2.         //引用文件
  3.         include "./Smarty/Smarty.class.php";
  4.         $smarty=new Smarty;
  5.         //var_dump($smarty);

  6.         $smarty->template_dir="./templates";//设置模板目录
  7.         $smarty->compile_dir="./templates_c";//设置编译目录。必选的。
  8.         $smarty->config_dir="Smarty/Config_File.class.php";//目录变量
  9.         $smarty->caching=false;//是否使用缓存,项目调试期间,不建议启用缓存
  10.         $smarty->cache_dir="./smarty_cache";//缓存文件夹.可选的。
  11.         $smarty->left_delimiter="<{";
  12.         $smarty->right_delimiter="}>";
  13. ?>
复制代码
建立一个模板文件xx.htm
  1. <html>
  2. <head>
  3.         <title>测试</title>
  4. </head>
  5. <body>
  6. <body>
  7.         欢迎<{$name}>光临smarty网站;
  8.         年龄:<{$age}>
  9. </body>
  10. </body>
  11. </html>
复制代码
建立一个php文件(i2.php)
  1. <?php
  2.         include('./smarty.php');
  3.         $name="dengwei";
  4.         $age=27;
  5.         $smarty->assign('name',$name);
  6.         $smarty->assign('age',$age);
  7.         #$smarty->display("./templates/xx.htm");
  8.         $smarty->display("./xx.htm");
  9. ?>
复制代码
而后访问 http://localhost/news/i2.php
结果报错了。。。根本没有显示预期的。。。求问是哪里出错了?

论坛徽章:
0
2 [报告]
发表于 2014-05-07 16:46 |只看该作者
解决了。smarty.php开头应该是
  1. <?php
复制代码
我就写了左尖括号和问号没写php。

另外虽然i2.php中写的是
  1. $smarty->display("./xx.htm");
复制代码
。但是xx.htm要放入到templates目录下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP