4

As in title, how can I get a list of all users in Magento ? Found already some examples but none of those works. All I managed to get was either only one user (myself) or nothing while I was expecting at least 3! Using this code as a result I'm getting ONE

$users = Mage::getModel('admin/user');

$usersCollection = $users->getCollection()->load();

foreach($usersCollection as $user){
    echo 'User: ' . $user->getFirstname() . '<br/>';
    echo 'User: ' . $user->getLastname() . '<br/>';
    echo 'User: ' . $user->getName() . '<br/>';
}

What am I doing wrong ?

2 Answers 2

3

To get all the Roles

$roles = Mage::getModel('admin/roles')->getCollection();
   foreach($roles as $role):
      echo '<br/>Role : '.$role->getId()." | ".$role->getRoleName();
   endforeach;

To get the Role users

$roles_users = Mage::getResourceModel('admin/roles_user_collection');
  foreach($roles_users as $roleuser):
   $user = Mage::getModel('admin/user')->load($roleuser->getUserId());
   echo '<br/>User : '.$user->getUsername()." | ".$user->getFirstname();
  endforeach;
1
  • Most Welcome :) Commented Mar 12, 2017 at 23:20
3

Please print the collection and then check data as same code worked for me.

$adminUser = Mage::getModel('admin/user');
$collection = $adminUser->getCollection()->load(); 
print_r($collection->getData());
1
  • Got it, so i must read first all the roles then users within each role right ?
    – Rob D. A.
    Commented Mar 12, 2017 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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