没想清楚,可能只有用递归了function foo() {
//...
$tpl->set_block("head","mnu_root","menu");
$tpl->set_var("ctopicname",VALUE);
$tpl->set_var("children",foo());
return $tpl->get_var("mnu_root");
}

解决方案 »

  1.   

    对,是死循环你得根据待填入的数据来判断是否进入嵌套
    function foo() {
    //...
    $tpl->set_block("head","mnu_root","menu");
    $tpl->set_var("ctopicname",VALUE);
    if($children)
      $tpl->set_var("children",foo());
    return $tpl->get_var("mnu_root");
    }
      

  2.   

    <?
    include("inc/template.inc.php");$title = array(1,2,3,4,5,6);
    $tpl = new Template("moban");
    $tpl->set_file("test", "test.htm");foo(reset($title));
    $tpl->pparse("o", "test");
    function foo($title) {
    global $tpl;
    global $title;
    $tpl->set_block("test","menu_root","menu");
    $tpl->set_var("menu");//我的系统中块好像都要这样设置一下才可以用
    $tpl->set_var("ctopicname", current($title));
    next($title);

    if($title[count($title)-1] != current($title))
    $tpl->set_var("children",foo($title));
    return $tpl->get_var("menu_root");
    }
    ?>
    这样子的代码输出有错误
    Notice: Undefined offset: 0 in D:\phpsite\hospital\inc\template.inc.php on line 110
    Notice: Undefined offset: 0 in D:\phpsite\hospital\inc\template.inc.php on line 110
    Notice: Undefined offset: 0 in D:\phpsite\hospital\inc\template.inc.php on line 110
    Notice: Undefined offset: 0 in D:\phpsite\hospital\inc\template.inc.php on line 110还有一个问题就是我的PHP平台在变量使用的时候都要声明一下,
    BLOCK块也要声明一下才可以用的。
    我的是PHP4.3.8+IIS+MYSQL的系统。
      

  3.   

    kaq 哎啊,老大们啊,我看不懂,,,呢。。郁闷
      

  4.   

    include "template.inc";
    $title = array(1,2,3,4,5,6);function foo() {
      global $title;
      $tpl = new template("../idedata");
      $tpl->set_file("head","test.htm");
      $tpl->set_block("head","mnu_root","menu");
      $tpl->set_var("ctopicname",array_shift($title));
      if(count($title) > 0)
        $tpl->set_var("children",foo());
      $tpl->parse("out","head");
      return $tpl->finish($tpl->get_var("out"));
    }echo foo();
    以上php4.3.2通过
    php5有警告信息(Notice: Undefined offset: 0),出现在set_block方法中。原因待查
      

  5.   

    谢谢老大了,功能已经实现了。
    就是有你说的这个警告信息,我的是PHP4.3.8的,
    我觉得和变量要先命名的情况有关系。