0

I'm creating a website where users can report on news in their area. Needless to say, I'm hoping to have thousands of users eventually.

I'm wondering what's the best way to give them a place to add/manage a biography about themselves. What should I do between the following options?

  1. Add a field in the user profile database and call the database on my template override

  2. Create a new content type named bio, treat it as a page and use entity/views to display the correct bio page based on the search

Originally I was going to go with the user database path, but something inside me is nagging me to treat bio's as pages for easier theming/searching. I think it's because I want the bio to be searchable like the articles are, and display as a whole page when selected without having to write a lot of backend code or more template overrides.

1

If the bio pages can be created for people without an account on the site, then I would create a new content type to use for the bio data; if the bio data needs to be strictly linked to the user profile, I would add new fields to the user accounts.

I would also create a new content type if I want the bio information to be completely searchable. When searching for users, the User module looks just for the username or the user email (in the case the user who is searching as the permission of administering users).

  $find = array();
  // Replace wildcards with MySQL/PostgreSQL wildcards.
  $keys = preg_replace('!\*+!', '%', $keys);
  $query = db_select('users')->extend('PagerDefault');
  $query->fields('users', array('uid'));
  if (user_access('administer users')) {
    // Administrators can also search in the otherwise private email field,
    // and they don't need to be restricted to only active users.
    $query->fields('users', array('mail'));
    $query->condition(db_or()->condition('name', '%' . db_like($keys) . '%', 'LIKE')->condition('mail', '%' . db_like($keys) . '%', 'LIKE'));
  }
  else {
    // Regular users can only search via usernames, and we do not show them
    // blocked accounts.
    $query->condition('name', '%' . db_like($keys) . '%', 'LIKE')->condition('status', 1);
  }

To search users basing on the content of any field attached to user accounts, you should use a module that implements user search differently from the User module, or create yourself one.

As for changing the template used for user accounts, that is not different from changing it for a node; the only difference is the template file used by default: user-profile.tpl.php for a user account, and node.tpl.php for a node.

You could also use the Profile 2 module; in this case, the profiles would be an entity different from nodes, and they would be fully searchable with the Views module or the Search API module.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.