你好,在自定义控制器中引入调用自定义递归函数出错。

#1 vsxp

Fatal error: Call to undefined function c_list() in  \htdocs\demo\include\info.phpon line
105其中c_list为递归函数名称,

2010-11-14 13:18:42

#2 vsxp

function c_list($parent_id=0,$level){
// 获得一个 父节点 $parent 的所有子节点
    $s='';
  
$rows = spClass('lib_category');
  
$condition = array('c_id_father'=>$parent_id,'c_active'=>1);
$results=$rows->findall($condition,'','c_id,c_name,c_run,c_id_father');
foreach ($results as $key=>$value)
{
  if ($value['c_id_father']==0)//判断父ID是否为0
  {
    $s.='显示父栏目名称';
  }else
  {
    $s.=str_repeat(' ',$level).'显示栏目';
  }
  c_list($value['c_id'],$level+1);
  //xdump($s);
}
    return $s;
}

2010-11-14 13:25:05

#3 jake

\htdocs\demo\include\info.php 这个文件在调用c_list()之前,有没有载入c_list()函数的内容呢?

2010-11-14 15:15:09

#4 vsxp

c_list()是 info.php中定义类 class show  下的一个函数,内容如下。
class show {
……
function c_list($parent_id=0……
  c_list($results['c_id'],$level+1);//调用自己  把这句注释掉运行正常,但只能查找一级内容,找不到子级的。

2010-11-14 15:59:56

#5 vsxp

\htdocs\demo\include\info.php 这个文件在调用c_list()之前,有没有载入c_list()函数的内容呢? ...
jake 发表于 2010-11-14 15:15
c_list()就定义在 \htdocs\demo\include\info.php里。是自定义函数自己调用自己。

2010-11-14 16:02:55

#6 jake

由于c_list是类show的成员函数,所以要按成员函数的方式来调用,不能用普通函数的调用方式,要以类成员函数调用的方式来调用。
class show {
……
function c_list($parent_id=0……
  $this->c_list($results['c_id'],$level+1);

2010-11-14 16:25:53

#7 vsxp

谢谢答复,这样后不出错,但用递归实现不了字符累计(连接)后再返回,总只能累计(连接)第一层的字符。
打算用别的办法实现。
再次感谢。JAKE

2010-11-16 01:10:26