Magento Asked by Fahad Bashir on February 12, 2021
Trying to get admin user id in Magento 2 helper,
in new at magento 2 any help will be appreciated.
Below is a helper with a dependency and you can see within one of its function how the backend user id is read
<?php
namespace MbsBackendScreenHelper;
use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;
class AdminUserReaderHelper extends AbstractHelper
{
/**
* @var MagentoBackendModelAuthSession
*/
private $authSession;
public function __construct(
Context $context,
MagentoBackendModelAuthSession $authSession
) {
parent::__construct($context);
$this->authSession = $authSession;
}
public function doSomethingWithMyAdminUserId()
{
...
if ($this->authSession->getUser() != null) {
$adminUserId = $this->authSession->getUser()->getId();
}
...
}
}
Answered by Herve Tribouilloy on February 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP