搞好了,但是老是提示找不到模板,是不是要设置class.smarttemplate.php里的template_dir参数,应该如何设置?我设了还是提示找不到??

解决方案 »

  1.   

    最好不要直接修改class.smarttemplate.php,而在实例化smarttemplate类之前定义$_CONFIG数组$_CONFIG = array(
    smarttemplate_compiled => "cache" /* temp_dir 编译临时文件目录 */,
    smarttemplate_cache => "cache" /* cache_dir 缓存目录 */,
    cache_lifetime => 600 /* cache_lifetime 最小编译周期 */,
    template_dir => "template_dir" /* template_dir 模板目录 */
    );
    相关变量的解释已在代码中了,目录可用相对路径或绝对路径,视需要而定。但不能没有。并请自行保证相关目录存在并可读写。数组$_CONFIG的作用很大,你可在模板中用模板函数config输出其中内容,而无须修改程序
    比如程序里有
    $_CONFIG['ip'] = $_SERVER['REMOTE_ADDR'];那么你想在页面中增加用户的ip地址时,就可以直接在模板里写入{config:"ip"}
    不必只在模板里写{ip},而在程序里写入$tpl->assign('ip',$_SERVER['REMOTE_ADDR']);
      

  2.   

    我设置了template_dir,但是还是提示找不到模板文件??
      

  3.   

    我这样new SmartTemplate('/var/www/html/template_dir/template.html'),就可以正常使用模板了,奇怪,那设置template_dir还有什么用??
      

  4.   

    $template_dir = ''/var/www/html/template_dir/';
      

  5.   

    $template_dir = ''/var/www/html/template_dir/';前面两个'?
    我是这样设置的
    template_dir => "/var/www/html/template_dir/";
    然后
    $template  =  new SmartTemplate('template.html'); 
    提示找不到
      

  6.   

    刚写的东西,吸是本地测试,你这样没有错,只有检查一下你的程序了
    $_CONFIG['smarttemplate_compiled']='./';
    $_CONFIG['smarttemplate_cache']='./';
    $_CONFIG['cache_lifetime']=0;
    $_CONFIG['template_dir']="E:/working/templates/";function show_news($id) {
    global $tpl_frame,$tpl_body,$tpl_header,$tpl_frame,$tpl_advertisement,$tpl_book,$tpl_keyword;
    $s_book=new SmartTemplate("$tpl_book");
    $r_book=$s_book->result(); $tpl_adv=new SmartTemplate("$tpl_advertisement");
    $r_adv=$tpl_adv->result();

    $tpl_key=new SmartTemplate("$tpl_keyword");
    $r_adv=$tpl_key->result(); $tpl_key=new SmartTemplate("$tpl_keyword");
    $r_adv=$tpl_key->result(); $s_body=new SmartTemplate("$tpl_body");
    $db_rows=_get_news_data($id);
    $s_body->assign('news_body',$db_rows['introduce);
    $s_body->assign('news_title',$db_rows->title);
    $s_body->assign('news_time',date('Y-m-d',$db_rows->date));
    $s_body->assign('news_from','');
    $s_body->assign('news_nav','');
    $r_body=$s_body->result();
    $page=new SmartTemplate("$tpl_frame");
    $page->assign('include_advertisement_tpl',$r_adv);
    $page->assign('include_book_menu_tpl',$r_book);
    $page->assign('include_keyword_tpl',$r_adv);
    $page->assign('news_main_of_tjzl_com',$r_body); $page->output();}