欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sae使用smarty模板的方法

程序员文章站 2022-07-03 12:28:12
smarty是非常流行的模板系统,它分离了业务和逻辑、执行速度快,在php网站中有广泛的运用。 不过在部署到sina app engine(sae)上时出现了问题,因为s...

smarty是非常流行的模板系统,它分离了业务和逻辑、执行速度快,在php网站中有广泛的运用。

不过在部署到sina app engine(sae)上时出现了问题,因为sae作为云计算平台式无法进行文件读写操作的,所以smarty中输出的缓存文件就无法实现。

错误信息:“sae_fatal_error: uncaught exception 'smartyexception' with message 'unable to write file ./web/templates_c/wrt4e95555280ef1' ”

sae给出了解决方案就是使用memcache。首先进入应用中的应用管理中,在服务管理中开启memcache一个初始化,

然后修改smarty的配置文件:

复制代码 代码如下:

// for sae 编译文件存放在memcache中
$smarty->compile_dir = 'saemc://smartytpl/';
$smarty->cache_dir = 'saemc://smartytpl/';
$smarty->compile_locking = false; // 防止调用touch,saemc会自动更新时间,不需要touch

上面三行是必须的。

这样smarty模板就可以在sae上运行了。