This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Learn » eZ Publish » Fetching User Objects with PHP - part 1

Fetching User Objects with PHP - part 1

Friday 24 September 2010 4:57:12 pm

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 2: Fetching individual users

A specific user can be pulled out of the system by Object ID, email address or their username (as we just did). We can also pull out the user based on the Node ID, but this means extracting the user information has to be approached slightly differently (we will cover this later in the tutorial). Below we use each method to pull out the same user. Since we have just pulled out the admin user, we will do the same here. If you are statically using a user in your script, I would advise using the email address or username where possible for clarity.

$users['name'] = eZUser::fetchByName( 'admin' );
$users['email'] = eZUser::fetchByEmail( '' );
$users['object_id'] = eZUser::fetch(14);
print_r( $users );

You should see from the results that they all return eZUser Objects.

Visualizing eZUser objects


Fetching the current user

If we were not running a standalone script and were instead adding some functionality to the CMS, we may need to pull out the currently logged in user. This can be done easily using the code below. Since we are using an automated script, we will not use this method further here (since this will return an anonymous user) :

$user = $users['name'];
$cli->output( 'Username: ' . $user->attribute('login') );
$cli->output( 'Email: ' . $user->attribute('email') );
36 542 Users on board!

Tutorial menu


Printer Friendly version of the full article on one page with plain styles


Proudly Developed with from