SMARTY不是这么用的...templates文件夹是用来放模板的xxx.tpl,因为这是一种模板语言啊...
而你说的那些图片链接都是基于调用模板的那个xxx.php页面的,所以链接位置根本不用templates/images/index_01.png这样。如果PHP页面与IMAGE文件夹一个目录的话,直接写images/index_01.png就可以了。建议LZ去搜下SMARTY的介绍文章,网上有不少的。

解决方案 »

  1.   

    感谢大家的帮助。可能我还不懂smarty的原理吧|||ichigoxi你好,你的意思是不是我要从新建一个专门放.HTML网页页面模板的文件夹,然后templates里全是.tpl文件?每个.tpl文件都是引用.html文件?
    genshing你好,我会试试你的方法的,呵呵谢谢。
      

  2.   

    文件夹分别是:cache       libs       require     templates   和     templates_c 
    在同级下再建images放图片,不要放在templates里
    而模板文件可以不用改为.tpl
    不过,建意改一下好
      

  3.   

    对,就是这个意思,既然是模板语言,肯定模板和php文件是分开的。这样代码上比较清晰。
    基本用法如下:
    //定义网站根目录
    define("SITE_ROOT","/web/vms/");
    define("WEB_ROOT","/vms");
    define("IMAGE_ROOT","/vms/images");//定义smarty模板类相关配置
    include SITE_ROOT."libs/Smarty.class.php";//定义数据库相关配置
    $db_host = "localhost";
    $db_user = "root";
    $db_password = "";
    $db_name = "cvs";$tpl = new Smarty();
    $tpl->caching = false;
    $tpl->template_dir = SITE_ROOT . "templates/";
    $tpl->compile_dir = SITE_ROOT . "templates_c/";
    $tpl->config_dir = SITE_ROOT . "configs/";
    $tpl->cache_dir = SITE_ROOT . "cache/";
    $tpl->left_delimiter = '<{';
    $tpl->right_delimiter = '}>';$tpl->assign("web_root",WEB_ROOT);
    $tpl->assign("image_root",IMAGE_ROOT);
    //定义页面title
    $tpl->assign("page_title","网站TITLE");你的PHP页再include这个页,调用tpl就OK了~祝你早日搞定
      

  4.   

    我比较喜欢的做法:
    $smarty->template_dir="./";
    跟templates目录说byebye~
      

  5.   

    1.在你的“localhoat”目录下建立新的目录learn/,在learn下建立目录
      smarty/,将刚才解压出来的目录的libs/拷贝到smarty/里,再在smarty/
      里新建templates目录,templates里新建cache/,templates/,templates_c/,
      config/,如下图所示
      
      --learn
         --smarty
            --libs
                --internals
                --plugins
            --templates
                --cache
                --configs
                --templates
                --templates_c
     
    2.新建一个模板文件:index.tpl 将此文件放在learn/smarty/templates/templates
       目录下,代码如下:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML4.01
    Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
          
    <html>
     <head>
      <meta http-equiv="Content-Type"   
                       content="text/html";charset="ge2312">
      <title>Smarty</title>
     </head>
     <body>
      {$hello}
     </body>
    </html>
     
    新建index.php 将此文件放在learn/下
     
    <?php
      //引用类文件
      require("smarty/libs/Smarty.class.php");
      $smarty=new Smarty;
      
      //设置各个目录的路径,这是安装的重点
      $smarty->template_dir="smarty/templates/templates";
      $smarty->compile_dir="smarty/templates/templates_c";
      $smarty->config_dir="smarty/templates/config";
      $smarty->cache_dir="smarty/templates/cache";
      
      //smarty模板具有高速缓存的功能,如果这里是true的话即打开caching,
      //但是会造成网页不会立即更新的问题,当然也可以通过其它的办法解决
      $smarty->caching=false;
     
      $hello="hello,world";
      $smarty->assign("hello",$hello);//对类模板中的变量赋值
      $smarty->display("index.tpl");//加载类模板
    ?>
     
    注:Smarty.class.php文件定义了类$Smarty及几个常量。
     
    3.执行index.php 就能在页面上输出"hello,world"先声明:我是抄别人的,不过我已经把一些东西改动了,你照上面的做 一定可以配置好,然后就明白SMARTY的原理了。
      

  6.   

    讲得很详细了,最近也在尝试了解smarty我觉得现在只需要了解应用层面上的东西就可以了,至于smarty后面的原理就不需要再深究了