echo $tpl->finish($tpl->get("out"));

解决方案 »

  1.   

    我的做法:
    一、修改template.inc
    加入以下的几个函数:
    /******************************************************************************
      函数:savetofile ($dir,$varname)
      功能:将分析结果保存到文件中去
      参数:$dir,$varname 文件路径,分析结果
      */
      function savetofile ($dir,$varname){
       $data=$this->finish($this->get_var($varname));
       $fp = fopen($dir,"w+");
       fwrite($fp,$data);
      }
     /******************************************************************************
      函数:renew ()
      功能:清除已赋值数组,以免批生成文件的时候变量之间相互影响
      参数:无
      */
       function renew(){
        $this->varkeys  = array();
        $this->varvals = array();
        //$this->file = array();
      }二、生成静态文件过程(仅供参考)
    function staticInfo($aid){
       global $db,$tbl,$template,$fpath,$file;   
       $sql="SELECT title,content,hits,title_name,come_from,writer,datetime FROM  $tbl where news_id=$aid";
       $db->query($sql);
       $db->next_record();
       //取出数据
       $template->set_var(array("content" => $db->f("content"),"title" => $db->f("title"),"datetime" => $db->f("datetime"),"writer" => $db->f("writer"),"come_from" => $db->f("come_from")));
       $template->parse("mains",$file);
       //把分析结果mains存入静态文件
       $filename = ARTICLE_PATH.$fpath."/".srandnum().time().".htm";
       $template->savetofile("../".$filename,"mains");
       echo $filename."<br>";
       //置空
       $template->renew();
       //把旧文件删除,新文件路径保存到数据库
       $sql = "select filepath from $tbl where news_id=$aid and checked=1";
       if($db->query($sql)){
          $db->next_record();
          @unlink("../".$db->f("filepath"));
       }
       //标识为已审核新闻
       $sql = "update $tbl set filepath='$filename',checked=1 where news_id=$aid";
       $db->query($sql);
    }
    $newslist = $_POST['fldTblList'];
    $id = explode(",",$newslist);for($i=0;$i<count($id);$i++){
    staticInfo($id[$i]);
    }
      

  2.   

    我想是不是有办法让PHPLIB只解析模板 但不输出结果 直接放到变量里呢?
    里面不是有一个get_var()函数吗?
    用这个可以取得解析后的模版。
      

  3.   

    $html  = $tpl->parse("out","view");这样就不会被输出了呀 内容会存入$html里了