2010-02-21 143 views
0

我意识到这有点含糊,但希望有人能够指出我在正确的方向。PHP致命错误 - 未定义函数

这是错误:致命错误:在线路调用未定义函数print_row()418

原因由该行:

**$something = profile_display_fields($css->id);** 

在此代码:

$customcss = get_records_select('user_info_field', '', 'sortorder ASC'); 

foreach ($customcss as $css) { 
    if ($css->name == 'usercss') { 
    $something = profile_display_fields($css->id); 
    } 
} 

这是行418:

print_row(s($formfield->field->name.':'), $formfield->display_data()); 

这里是全功能:

function profile_display_fields($userid) { 
    global $CFG, $USER; 

    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) { 
     foreach ($categories as $category) { 
      if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) { 
       foreach ($fields as $field) { 
        require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php'); 
        $newfield = 'profile_field_'.$field->datatype; 
        $formfield = new $newfield($field->id, $userid); 
        if ($formfield->is_visible() and !$formfield->is_empty()) { 
         print_row(s($formfield->field->name.':'), $formfield->display_data()); 
        } 
       } 
      } 
     } 
    } 
} 
+7

哪里是'print_row()'定义?错误是因为PHP无法找到它。 – 2010-02-21 18:09:56

回答

1

看起来像moodle的profile_display_fields()在user/profile/lib.php中定义。

print_rows()函数在user/view.php中定义。确保在调用profile_display_fields()之前包含此文件。

编辑:

function print_row($left, $right) { 
    echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n"; 
} 

这是print_rows的 “原始” 的定义()。如果你使用user/profile/lib.php而不是view.php,将它定义在某处。

编辑:我不喜欢它,但你可以做一个函数定义的条件,以避免“致命错误:不能重新申报功能XYZ”

if (!function_exists('print_row')) { 
    function print_row($left, $right) { 
    echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n"; 
    } 
} 
+0

鉴于此,是'print_row(s'一个错字? – Greg 2010-02-21 18:53:51

+0

不,问题中的代码似乎是从lib.php 1:1的副本我刚刚下载了moodle-weekly-19,它是一样的。btw:它的打印\ _row(s(...),...),无论函数s()如何;这是我第一次听说“moodle”;-) – VolkerK 2010-02-21 18:58:12

+0

欢迎来到Moodle的世界哈哈 增加了功能和代码的作品! – CLiown 2010-02-21 19:56:42

2

的错误是正确地指出,我无法找到代码中的某处定义功能print_row。确保你定义了这个函数,看起来这个函数是存在于其他文件中的,试着在其他文件中搜索这个函数,并将这个文件包含在你的脚本中,这个错误不会再出现。

0

您的代码失败,出现此错误的原因:

  • print_row()不是PHP核心
  • 的功能部:无PHP扩展定义print_row()
  • 您的代码还没有定义了一个名为print_row()功能在执行该声明之前。

如果print_row()在外部文件中定义,确保该文件包含之前调用该函数。

相关问题