现在的位置: 首页 > 综合 > 正文

[ php ] php smarty使用!

2014年06月27日 ⁄ 综合 ⁄ 共 792字 ⁄ 字号 评论关闭

1 在你的网站目录下创建一个文件夹,名字任意,假设叫smarty_demo:

2  然后再在这个MySmarty目录下创建2个文件夹,templates和configs。 

 创建完成之后如下:    (你的网站目录)/smarty_demo/templates (这个目录用来存放模版) 

 (你的网站目录)/smarty_demo/configs (这个目录用来存放一些配置信息)

3、在smart_demo目录下再创建两个文件夹,名字分别叫:smarty_cache和smarty_templates_c。为什么刚才不一起创建呢?因为这个步骤在原来的官方资料中没有,而我在配置过P中发现,如果没有这两个文件夹,smarty将无法工作,不知道是不是官方资料的smarty版本和目前最新的版本有出入的原因。但是只要配置这两个目录,Smarty便可以顺利工作。因此建议进行配置。

<?php
    require('smarty/Smarty.class.php');
    $smarty = new Smarty;

    $smarty->template_dir   = 'D:/AppServ/www/smarty_demo/templates/';

    $smarty->config_dir     = 'D:/AppServ/www/smarty_demo/configs/';

    $smarty->cache_dir      = 'D:/AppServ/www/smarty_demo/smarty_cache/';

    $smarty->compile_dir    = 'D:/AppServ/www/smarty_demo/smarty_templates_c/';

    $smarty->assign('name','helloword');

    $smarty->display('index.tpl');

?>

<html>
    <body>
        {$name}!;
    </body>
</html>

抱歉!评论已关闭.