smarty在windows下的安装
简述
1. 从http://smarty.php.net/上下载压缩包Smarty-2.6.14.tar.tar,解压并重新命名,我将其命名为 
   smarty。
2. 将解压后的文件夹放在自己感觉方便的目录下,我放在了php的安装目录e:\APMServ\PHP\下。
3. 修改php的配置文件php.ini,找到;include_path = ".;c:\php\includes",在其下面一行添加语 
   句include_path = ".;e:\APMServ\PHP\smarty\libs",重启web服务器。
4. 在自己感觉方便的目录下建立smarty运行时需要的四个文件夹,我把他们都建立在了web目录下的工程文 
   档下,我的一个web工程名为files_upload,位置是www/files_upload.
   建立文件夹files_upload\smarty\temlpates
           files_upload\smarty\temlpates_c
           files_upload\smarty\cache
           files_upload\smarty\configs
   安装完成。
5. 建立模板文件index.tpl放在files_upload\smarty\temlpates下
   index.tpl的内容为:   
<html>
<body>
Hello, {$name}!
</body>
</html>
<html>
<body>
Hello, {$name}!
</body>
</html>
   建立index.php文件内容为:
   <?php
   require('Smarty.class.php');
   $smarty = new Smarty;
   $smarty->template_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/temlpates';
$smarty->config_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/configs';
$smarty->cache_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/cache';
$smarty->compile_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/templates_c';
$smarty->config_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/configs';
$smarty->cache_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/cache';
$smarty->compile_dir = 'e:/APMServ/www/htdocs/files_upload/smarty/templates_c';
   $smarty->assign('name','fish boy!');
$smarty->display('index.tpl');
?>
$smarty->display('index.tpl');
?>
   通过浏览器访问index.php,执行结果为:Hello, fish boy!! 
总结:1. 关于require('Smarty.class.php');
        要让系统找到Smaty.class.php文件,它被放置在smarty\libs下,所以在配置文件php.ini中
        添加了语句include_path = ".;e:\APMServ\PHP\smarty\libs"。
        如果不想修改php.ini文件,就要在index.php中的require语句将Smarty.class.php的绝对路
        径写出来。
     2. 关于 建立文件夹files_upload\smarty\temlpates
 
                     files_upload\smarty\temlpates_c
                     files_upload\smarty\cache
                     files_upload\smarty\configs
        经常用到的是templates 文件夹,所有的模板文件都要放在这个文件夹下。
        四个文件夹的可以放在自己方便的地方,只要在index.php中的路径变量的值和实际放置的路 
        径相同便可以。
如果上述输出错误,请确保文件夹的权限是不否有问题,我第一次安装进也是出错了,修改权限后就可以了.
     修改的权限包括smarty文件夹
    凡事往简单处想,往认真处行
                    
                
                
            
        
浙公网安备 33010602011771号