根目录下有templates templates_c configs cache文件夹 下面代码为何报错?Fatal error: Smarty error: the $compile_dir '/templates_c/' does not exist, or is not a directory. 
[code]require_once('class/libs/Smarty.class.php');$smarty=new Smarty();
$smarty->template_dir = '/templates/';  
$smarty->compile_dir = '/templates_c/';   //把这个注解就不会报错,而templates_c里也会生成缓存文件,因为用了Smarty类的默认路径
$smarty->config_dir = '/configs/';
$smarty->cache_dir = '/cache/';
$smarty->display('header.html');[/code]

解决方案 »

  1.   

    这个目录应该是没有的吧 /templates_c/ 表示你的系统的根目录,而不是你当前网站的根目录
      

  2.   

    应该是php无法访问到根目录,
    看看php.ini设定,是不是开启safe_mode的缘故。
      

  3.   

    /templates_c/
    根目录没有这个目录
      

  4.   

    templates_c/ 目录不存在
    可能原因是目前指向错误,
    echo $smarty-> $compile_dir;
    看看路径是什么?然后看看是否真的存在这样的目录。
      

  5.   

    在生成smarty类的实例后指定一个模板缓存目录,即你的例子中的template_c,要保证这个目录是相对于你目前文件的
      

  6.   

    require_once('class/libs/Smarty.class.php');$smarty=new Smarty();
    $smarty->template_dir = '/templates/'; 
    $smarty->compile_dir = '/templates_c/';  //把这行注解掉,就不报错了,而且在根目templates_c下也会生成缓存文件
    $smarty->right_delimiter = '}-->';
    $smarty->display('header.html');
      

  7.   

    打印出来的是
    /templates_c/这路径
      

  8.   

    /aa/bb 这个是绝对路径,不是相对路径,而且你最好用绝对路径
    你可以使用
    $_SERVER['DOCUMENT_ROOT']."/templates_c/" 这个样子来表示当前网站的根目录的templates_c 这个目录(虚拟主机)。
      

  9.   

    今天刚写了个配置smarty的教程,你参考参考吧!http://hi.baidu.com/hdxiaopihai/blog/item/e8a859f0c99311a7a50f5230.html
      

  10.   

    相对于你调用smarty 的根目录建个文件夹templates_c就行了