Friday 24 September 2010 7:57:12 am
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( 'admin@admin.com' ); $users['object_id'] = eZUser::fetch(14); print_r( $users );
You should see from the results that they all return eZUser Objects.
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') );