新浪云SAE SpeedPHP配置Smarty

快速入门六、用Smarty来显示页面 

PHP模板之Smarty安装与使用入门教程

想要在SpeedPHP中搭建Smarty

于是找了上面两个文档进行学习,(我的搭建方法是参考了文档PHP模板之Smarty安装与使用入门教程

Smarty我删掉了SpeedPhp自带的(SpeedPHP/Drivers 目录下可以看到),从官网重新下载,

不过在搭建好后出了问题,SAE不支持本地文件写入

        define('SMARTY_ROOT',  APP_PATH.'/smarty/tpls');
        include(APP_PATH.'/smarty/libs/Smarty.class.php');
        $tpl = new Smarty();
        $tpl->template_dir = SMARTY_ROOT."/templates/";
        $tpl->compile_dir = SMARTY_ROOT."/templates_c/";
        $tpl->config_dir = SMARTY_ROOT."/configs/";
        $tpl->cache_dir = SMARTY_ROOT."/cache/";
        $tpl->caching=1;
        $tpl->cache_lifetime=60*60*24;
        $tpl->left_delimiter = '<{';
        $tpl->right_delimiter = '}>';
        $tpl->display("leapsoul.tpl");


以上为 PHP模板之Smarty安装与使用入门教程文档中程序片段。执行该代码的时候会报错:

User error: Smarty error: the $compile_dir '/****************/1/smarty/tpls/templates_c/' does not exist, or is not a directory. in smarty/libs/Smarty.class.php on line 1094

参照针对SAE程序员常问的问题 的解决方法,

不直接定义编译目录路径 $tpl->compile_dir = SMARTY_ROOT."/templates_c/";

改成:

        $path="saemc://templates_c";
        mkdir($path);
        $tpl->compile_dir = $path;
并注释掉

//$tpl->caching=1;
再运行便可以了。

更改后代码片如下:

        define('SMARTY_ROOT',  APP_PATH.'/smarty/tpls');
        include(APP_PATH.'/smarty/libs/Smarty.class.php');
        $tpl = new Smarty();
        $path="saemc://templates_c";
        mkdir($path);
        $tpl->compile_dir = $path;
        $tpl->template_dir = SMARTY_ROOT."/templates/";
        $tpl->config_dir = SMARTY_ROOT."/configs/";
        $tpl->cache_dir = SMARTY_ROOT."/cache/";
        //  $tpl->caching=1;//加了这句就不行,待解决
        $tpl->cache_lifetime=60*60*24;
        $tpl->left_delimiter = '<{';
        $tpl->right_delimiter = '}>';
        $tpl->display("leapsoul.tpl"); 

附上代码结构和主要代码截图:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值