<?php
 require('Smarty.class.php');   
 $smarty = new smarty();
 $smarty->template_dir ='E:/PHPCode/sp/Smarty/templates';   
 $smarty->config_dir = 'E:/PHPCode/sp/Smarty/config';   
 $smarty->cache_dir ='E:/PHPCode/sp/Smarty/cache';   
 $smarty->compile_dir ='E:/PHPCode/sp/Smarty/templates_c';    
 $smarty->assign('hello','Hello World!');
 $smarty->display('index.tpl');
?> 
以上代码存为:'E:/PHPCode/sp/index_Smarty.php"E:/PHPCode/sp"是我的虚拟目录;
index.tpl文件放在'E:/PHPCode/sp/Smarty/templates'下;
我的php.ini文件的include_path是“include_path = ".;E:\smarty\libs"”
在浏览器中打开时,提示:Parse error: syntax error, unexpected T_VARIABLE in E:\PHPCode\sp\index_Smarty.php on line 3感觉是Smarty没有注册上,大家帮忙看看!

解决方案 »

  1.   

    E:\smarty\libs要加入道windows的环境配置的path变量中。
      

  2.   

    我用的smarty是2.6.26版本的,php5.3.1;Apache2.2;
      

  3.   

    或者在代码中加入:define('SMARTY_DIR', 'E:/smarty/libs');
    具体的配置可以参看smarty的安装说明,如下:
    http://www.smarty.net/manual/en/installing.smarty.basic.php
      

  4.   


    这是我的php.ini
    ;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Paths and Directories ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; UNIX: "/path1:/path2"
    ;include_path = ".:/php/includes"
    ;
    ;Windows: "\path1;\path2"
    include_path = ".;E:\smarty\libs"这样不对吗?
      

  5.   

    是加入到windows的环境变量,不是修改php.ini。
    windows环境变量是在右击"我的电脑"->高级->"环境变量"->"系统变量"->"Path"
      

  6.   


    已经修改了系统变量,又重启了apache,现在提示:
    Parse error: syntax error, unexpected T_REQUIRE in E:\PHPCode\sp\index_Smarty.php on line 2
    现在找不着
    <?php
       define('SMARTY_DIR', 'E:/Smarty/libs/');    //提示第二行
       require_once(SMARTY_DIR . 'Smarty.class.php');   
       $smarty = new Smarty();
    .....
    ?>
      

  7.   

    以前提示:unexpected T_VARIABLE,
    现在提示:unexpected T_STRING
      

  8.   

    不是这些的原因,我终于明白了,我配置的信息是正确的。
    是因为我使用的例子是网上找来的,都是源代码。里面加有空格。
    我重新手工录入了一份就可以显示出“Hello World!”。