1

我已经编写了这段代码,它profile_display_fields为 $USER 输出:

$appearance = profile_display_fields($USER->id);
        if (empty($appearance)) {
            //Do nothing
        } else {
            foreach ($appearance as $c) {
            $custom .= '<a href=\''.$CFG->wwwroot.'/course/view.php?id='.$c->id.'\'>'.$c->fullname.'</a>';
            }
        }

这是我正在使用的功能:

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());
                    }
                }
            }
        }
    }
}

我要做的是尝试一些var_dumps 来输出正确的数据。

但是,任何人都可以帮我识别变量吗?

4

1 回答 1

1

In your function you are not returning any value but above that in your code, you have assigned a variable to this function:

$appearance = profile_display_fields($USER->id);

You need to return some variable/data from the function and that is the one to be var dumped.

I suppose you are using the print_row to print the data, not returning the response to be used out of the function.

于 2010-02-21T12:21:37.617 回答