tags:

views:

92

answers:

3

I realise this is a bit vague but hoping someone might be able to point me in the right direction.

This is the error: Fatal error: Call to undefined function print_row() on line 418

Cause by this line:

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

In this code:

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

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

Here is line 418:

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

And here is the whole function:

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());
                    }
                }
            }
        }
    }
}
+2  A: 

The error is rightly pointed, i could not find the function print_row defined somewhere in your code. Make sure that you define that function, it looks like that function is present in some other file, try searching for this function in other files and include that file in your script and this error won't show up again.

Sarfraz
A: 

Your code fails with this error because:

  • print_row() is not a function part of the PHP Core
  • No PHP extension is defining print_row()
  • Your code hasn't defined a function called print_row() before the execution of that statement.

If print_row() is defined in an external file, make sure that this file is included before calling the function.

Andrew Moore
+1  A: 

That looks like moodle's profile_display_fields() defined in user/profile/lib.php.

The print_rows() function is defined in user/view.php. Make sure this file is included prior to the call of profile_display_fields().

edit:

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

That's the "original" definition of print_rows(). Define it somewhere in case you're using user/profile/lib.php but not view.php.

edit: I don't like it, but you can make a function definition conditional to avoid "fatal error: cannot re-declare function 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";
  }
}
VolkerK
Given this, is `print_row(s` a typo?
Greg
No, the code in the question seems to be a 1:1 copy from lib.php I just downloaded moodle-weekly-19 and it's the same. btw: it's print\_row(s(...), ...), whatever function s() does; it's the first time I heard of "moodle" ;-)
VolkerK
Welcome to the world of Moodle lolAdded the function and the code works!
danit
The trouble is this function is already declared on some pages where I want to use my code and it screws up?
danit
see edit........
VolkerK