今天开始在新浪sae中配置smarty,按照在本地配置照搬到sae上,结果报错:
SAE_DEBUG: Smarty error: the $compile_dir './template_c' does not exist, or is not a directory.
在网上查了一下,大体上说原因是 SAE由于考虑到安全和分布式问题,所以本地IO写是禁止的,之后也查了百度 可是大部分都是转载的 都没有成功.
也没找到专门的sae版本的smarty, 只能修改其源码结合memcache来兼容了. 我用的是smarty3
1. 打开sae中你的应用,点击左下方服务管理中的Memcache,然后点击初始化,设置好容量大小(我设置为16M),这样,Memcache就配置好了。


2.在你的入口index.php 初始化memcache
<?php
//这段代码要放在入口文件
global $mmc; //设为全局变量 这样smarty才能访问
$mmc = new Memcache;
$ret = $mmc->connect();
if ($ret == false) {
echo "缓存开启错误\n";
exit;
}
$ret = $mmc->connect();
if ($ret == false) {
echo "缓存开启错误\n";
exit;
}
?>
3.更改smarty配置文件中的编译目录和缓存随意就行
$smarty->compile_dir = 'compile_dir';
$smarty->cache_dir = 'cache_dir';
4.修改 smarty/internals/core.write_compiled_resource.php 里面的 smarty_core_write_compiled_resource 函数为下面的格式
function smarty_core_write_compiled_resource($params, &$smarty)
{
$_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
require_once(SMARTY_CORE_DIR . 'core.write_file.php');
smarty_core_write_file($_params, $smarty);
return true;
}
{
$_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true);
require_once(SMARTY_CORE_DIR . 'core.write_file.php');
smarty_core_write_file($_params, $smarty);
return true;
}
5.修改 smarty/internals/
core.write_file.php 里面的
core.write_file.php 函数为下面的格式
function smarty_core_write_file($params, &$smarty)
{
global $mmc;
$file = $params['filename'];
$content = $params['contents'];
$mmc->set("$file", $content);
return true;
}
{
global $mmc;
$file = $params['filename'];
$content = $params['contents'];
$mmc->set("$file", $content);
return true;
}
6.最后修改 Smarty.class.php里的一些代码 我的版本是在1264行 你们可以自己搜索下
if ($this->_is_compiled($resource_name, $_smarty_compile_path) || $this->_compile_resource($resource_name, $_smarty_compile_path))
{
{
//
include($_smarty_compile_path); //这是源代码
include("saemc://".$_smarty_compile_path); //这是修改后的
}
include("saemc://".$_smarty_compile_path); //这是修改后的
}
7.这样大概就可以了 假如还是出错 那继续就一步一步的修改吧. 或者联系我