是这样的,class.smarttemplate.php有一个bug
你需要将
unset ($_top);
改为
unset ($GLOBALS[_top]);只有这一处在output方法中

解决方案 »

  1.   

    用$_top是提供模板嵌套功能吧,
    不过我看output方法中并没有对$_top是数组的情况进行处理,
    也就是说声明$_top是全局的没有起到什么作用吧。
    如果不想使用模板嵌套的功能去掉他就行了吧
      

  2.   

    我认为
    $tpl 是一个class的实例.
    也就是说 $tpl->assign("a",$a);
    是让$tpl中的一个变量a等于$a
    和$a = a; 是一样的..
    你用循环就=====
    for($i=0;$i<10:i++){
       $a = "a";
    }
    是不可能 让$a 就变成一个数组
      

  3.   

    首先不要去瞎猜,照我说的做是没错的。输出012
    我是在刚接触到这个东西,也发现类似的问题时在网上找到的答案至于为什么要声明$_top我并没有认真研究 function output ( $_top = '' )
    {
    global $_top; // Make sure that folder names have a trailing '/'
    if (strlen($this->template_dir)  &&  substr($this->template_dir, -1) != '/')
    {
    $this->template_dir  .=  '/';
    }
    if (strlen($this->temp_dir)  &&  substr($this->temp_dir, -1) != '/')
    {
    $this->temp_dir  .=  '/';
    }
    // Prepare Template Content
    if (!is_array($_top))
    {
    if (strlen($_top))
    {
    $this->tpl_file  =  $_top;
    }
    $_top  =  $this->data;
    }
    $_obj  =  &$_top;
    $_stack_cnt  =  0;
    $_stack[$_stack_cnt++]  =  $_obj; // Check if template is already compiled
         $this->cpl_file  =  $this->temp_dir . preg_replace('/[:\/.\\\\]/', '_', $this->tpl_file) . '.php';
    $compile_template  =  true;
    if ($this->reuse_code)
    {
    if (is_file($this->cpl_file))
    {
    if ($this->mtime($this->cpl_file) > $this->mtime($this->template_dir . $this->tpl_file))
    {
    $compile_template  =  false;
    }
    }
    }
    if ($compile_template)
    {
    include_once ("class.smarttemplateparser.php");
    $this->parser = new SmartTemplateParser($this->template_dir . $this->tpl_file);
    if (!$this->parser->compile($this->cpl_file))
    {
    exit( "SmartTemplate Compiler Error: " . $this->parser->error );
    }
    }
    // Execute Compiled Template
    include($this->cpl_file); // Delete Global Content Array in order to allow multiple use of SmartTemplate class in one script
    // unset ($_top);
    unset ($GLOBALS[_top]);
    }
      

  4.   

    是的,按照你的方法已经解决问题了,我想也正是由于全局的TOP变量让模板每次加载的数据都一样的。
    再次感谢唠叨老大!
    结贴