I have a magento installation I want to access the logged in admin credentials in a file inside a subfolder. I make a file and keep it in the root (the same folder where the magento index.php resides). It shows me the logged in user data perfectly. Now when I copy the same file inside a subfolder it returns the data but the data array(which contains the loggedin user information) is empty. Below is the code
require_once ('app/Mage.php');
Mage::app();
$user = Mage::getSingleton('admin/session');
print_r($user);
1 Answer 1
The proper way to get the current logged in admin user in a sub folder is as below.
require_once ('../app/Mage.php');
$admin = Mage::getSingleton('admin/session')->getUser();
As the custom file is in a sub folder at the root of the magento, so you have to include Mage.php properly as mentioned in above code.
Now you can fetch different admin properties as below:
$admin->getId(); //Get ID
$admin->getUserName() //Get user name
Hope this helps.
Thank you
-
The same issue the code you provided works in the file that is in the root. But inside php file in the folder when I paste this it says Call to a member function getId() on a non-objectAbdulBasit– AbdulBasit2016年05月31日 10:48:15 +00:00Commented May 31, 2016 at 10:48