Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

Some problems, and their solutions:

  1. Never use the PHP input filterPHP input filter.

  2. When you are developing code, ensure that you have proper error reporting on. This would show you that you have a problem on the $account = line.

  3. PHP 5.3: E_ALL | E_STRICT

  4. PHP 5.4: E_ALL.

  5. Your general problem is not in code per se, but in not understanding how to debug code. If you have devel installed, you can dpm() values on a line per line basis, in an attempt to nail down the problem. If you were to do that, you would quickly notice that $account does not contain the values you expect. $user>uid is actually a mathematical operation, and will not return the users uid. What you want is $user->uid.

  6. field_view_value() will, as the documentation suggests, return "a renderable array", it's not going to actually give you meaningful output, and since it's an array, you can't print it.

I'm guessing what you actually want is:

<?php
global $user;
$account = user_load($user->uid);
$school_cats = field_get_items('user', $account, 'field_user_school_category');
foreach ($school_cats as $school_cat) {
  print $school_cat['safe_value'];
}

Some problems, and their solutions:

  1. Never use the PHP input filter.

  2. When you are developing code, ensure that you have proper error reporting on. This would show you that you have a problem on the $account = line.

  3. PHP 5.3: E_ALL | E_STRICT

  4. PHP 5.4: E_ALL.

  5. Your general problem is not in code per se, but in not understanding how to debug code. If you have devel installed, you can dpm() values on a line per line basis, in an attempt to nail down the problem. If you were to do that, you would quickly notice that $account does not contain the values you expect. $user>uid is actually a mathematical operation, and will not return the users uid. What you want is $user->uid.

  6. field_view_value() will, as the documentation suggests, return "a renderable array", it's not going to actually give you meaningful output, and since it's an array, you can't print it.

I'm guessing what you actually want is:

<?php
global $user;
$account = user_load($user->uid);
$school_cats = field_get_items('user', $account, 'field_user_school_category');
foreach ($school_cats as $school_cat) {
  print $school_cat['safe_value'];
}

Some problems, and their solutions:

  1. Never use the PHP input filter.

  2. When you are developing code, ensure that you have proper error reporting on. This would show you that you have a problem on the $account = line.

  3. PHP 5.3: E_ALL | E_STRICT

  4. PHP 5.4: E_ALL.

  5. Your general problem is not in code per se, but in not understanding how to debug code. If you have devel installed, you can dpm() values on a line per line basis, in an attempt to nail down the problem. If you were to do that, you would quickly notice that $account does not contain the values you expect. $user>uid is actually a mathematical operation, and will not return the users uid. What you want is $user->uid.

  6. field_view_value() will, as the documentation suggests, return "a renderable array", it's not going to actually give you meaningful output, and since it's an array, you can't print it.

I'm guessing what you actually want is:

<?php
global $user;
$account = user_load($user->uid);
$school_cats = field_get_items('user', $account, 'field_user_school_category');
foreach ($school_cats as $school_cat) {
  print $school_cat['safe_value'];
}
Source Link
Letharion
  • 27.5k
  • 11
  • 83
  • 141

Some problems, and their solutions:

  1. Never use the PHP input filter.

  2. When you are developing code, ensure that you have proper error reporting on. This would show you that you have a problem on the $account = line.

  3. PHP 5.3: E_ALL | E_STRICT

  4. PHP 5.4: E_ALL.

  5. Your general problem is not in code per se, but in not understanding how to debug code. If you have devel installed, you can dpm() values on a line per line basis, in an attempt to nail down the problem. If you were to do that, you would quickly notice that $account does not contain the values you expect. $user>uid is actually a mathematical operation, and will not return the users uid. What you want is $user->uid.

  6. field_view_value() will, as the documentation suggests, return "a renderable array", it's not going to actually give you meaningful output, and since it's an array, you can't print it.

I'm guessing what you actually want is:

<?php
global $user;
$account = user_load($user->uid);
$school_cats = field_get_items('user', $account, 'field_user_school_category');
foreach ($school_cats as $school_cat) {
  print $school_cat['safe_value'];
}