2010-02-21 193 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()在外部文件中定義,確保該文件包含之前調用該函數。