0

How can i add more argument \Magento\Backend\Model\Auth\Session $authSession into \Magento\Store\Model\Website ?

I tried to get current user like following link: Magento 2: How to get current admin user detail?

and it gave me error log:

Recoverable Error: Argument 14 passed to Magento\Store\Model\Website::__construct() must be an instance of Magento\Backend\Model\Auth\Session, array given, called in D:\tait_magento\trunk\var\generation\Magento\Store\Model\Website\Interceptor.php on line 14 and defined in D:\tait_magento\trunk\vendor\magento\module-store\Model\Website.php on line 199.

Block dashboard throws exception and cannot be rendered.

And i have search and do everything from clearing /var/* folders or config di.xml but i can't have any results.

Please help me , the beginner with Magento 2.

This is my code:

    namespace Magento\Store\Model;

     class Website extends \Magento\Framework\Model\AbstractExtensibleModel implements
        \Magento\Framework\DataObject\IdentityInterface,
        \Magento\Framework\App\ScopeInterface,
        \Magento\Store\Api\Data\WebsiteInterface
    {

    ....

         protected $_authSession;
         public function __construct(
                \Magento\Framework\Model\Context $context,
                \Magento\Framework\Registry $registry,
                \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
                \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
                \Magento\Config\Model\ResourceModel\Config\Data $configDataResource,
                \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
                \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory,
                \Magento\Store\Model\GroupFactory $storeGroupFactory,
                \Magento\Store\Model\WebsiteFactory $websiteFactory,
                \Magento\Store\Model\StoreManagerInterface $storeManager,
                \Magento\Directory\Model\CurrencyFactory $currencyFactory,
                \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
                \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        //        \Magento\Backend\Model\Auth\Session $authSession,
                array $data = []
            ) {
                parent::__construct(
                    $context,
                    $registry,
                    $extensionFactory,
                    $customAttributeFactory,
                    $resource,
                    $resourceCollection,
                    $data
                );
                $this->_configDataResource = $configDataResource;
                $this->_coreConfig = $coreConfig;
                $this->storeListFactory = $storeListFactory;
                $this->_storeGroupFactory = $storeGroupFactory;
                $this->_websiteFactory = $websiteFactory;
                $this->_storeManager = $storeManager;
                $this->_currencyFactory = $currencyFactory;

                //$authSession = new Session();
               // $this->_authSession = $authSession;
            }

            protected function _construct()
            {
                $this->_init('Magento\Store\Model\ResourceModel\Website');
            }

            public function getCurrentUser()
            {
                return $this->_authSession->getUser();
            }
......
    }
1

Required parameters must be before optional.

        public function __construct(
            \Magento\Framework\Model\Context $context,
            \Magento\Framework\Registry $registry,
            \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
            \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
            \Magento\Config\Model\ResourceModel\Config\Data $configDataResource,
            \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
            \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory,
            \Magento\Store\Model\GroupFactory $storeGroupFactory,
            \Magento\Store\Model\WebsiteFactory $websiteFactory,
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            \Magento\Directory\Model\CurrencyFactory $currencyFactory,
            \Magento\Backend\Model\Auth\Session $authSession, // <-- your dependensies
            \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
            \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
            array $data = []
        )
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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