这是目录结构,smarty放置在common文件夹下面,我希望user下可以放置php文件,如图写的稍微详细一点,最好是有点注释,新手,谢谢!

解决方案 »

  1.   

     include "../libs/Smarty.class.php"; 
    $NowPathArray=explode("test",str_replace("\\","/",dirname(__FILE__))) ;
        @define("root_path", $NowPathArray[0]);
        @define('__SITE_ROOT', root_path."test"); 
        $tpl = new Smarty(); 
        $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 = '}>'; 路径 需要你 根据实际情况而定
      

  2.   

    难道是这样;D:.
    ├─common
    │  └─smarty
    │      ├─internals
    │      └─plugins
    └─user
        ├─templates
        └─templates_c
        └——demo2.php
    demo2.php<?php
    require_once('../common/smarty/Smarty.class.php');
    $smarty = new Smarty();
    $smarty->compile_dir=dirname(__FILE__)."/templates_c";
    $smarty->template_dir=dirname(__FILE__)."/templates";
    $smarty->caching=false; 
    $smarty->left_delimiter="<{";
    $smarty->right_delimiter="}>"; 
    $smarty->assign("abc","eeeeeeee");
    $smarty->display("demo2.tpl");