0

I am working on a Magento 2.1.7 shop. To achieve this, I have created a child-theme of Magento Blank.

I have installed the Bannerslider module.

I run the commands:

  1. php bin/magento module:enable Magestore_Bannerslider
  2. php bin/magento setup:upgrade
  3. php bin/magento setup:di:compile

All was ok in my local development environment, but on staging environment I get an error Incorrect dependency in class Magestore\Bannerslider\Controller\Index in /var/www/staging.domain.com/app/code/Magestore/Bannerslider/Controller/Index.php \Magento\Framework\ObjectManagerInterface already exists in context object in the console.

Also, Error log record number: 1455276823131 error in the browser (frontend).

Why is that? What is the fix? Thank you!

1 Answer 1

0

Add this line in your _construct function

$this->_objectManager = $context->getObjectManager();

/var/www/staging.domain.com/app/code/Magestore/Bannerslider/Controller/Index.php

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magestore\Bannerslider\Model\SliderFactory $sliderFactory,
    \Magestore\Bannerslider\Model\BannerFactory $bannerFactory,
    \Magestore\Bannerslider\Model\ReportFactory $reportFactory,
    \Magestore\Bannerslider\Model\ResourceModel\Report\CollectionFactory $reportCollectionFactory,
    \Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
    \Magento\Framework\Logger\Monolog $monolog,
    \Magento\Framework\Stdlib\DateTime\Timezone $stdTimezone
) {
    parent::__construct($context);
    $this->_sliderFactory = $sliderFactory;
    $this->_bannerFactory = $bannerFactory;
    $this->_reportFactory = $reportFactory;
    $this->_reportCollectionFactory = $reportCollectionFactory;
    $this->_resultRawFactory = $resultRawFactory;
    $this->_monolog = $monolog;
    $this->_stdTimezone = $stdTimezone;
    $this->_objectManager = $context->getObjectManager(); // Add this line
}
10
  • my file has this code: $this->_stdTimezone = $stdTimezone; $this->_objectManager = $objectManager;. Shall I replace the last line with $this->_objectManager = $context->getObjectManager();? Nov 20, 2017 at 15:23
  • yes please... also check this link github.com/Magestore/Bannerslider-Magento2/pull/90/… Nov 20, 2017 at 15:24
  • And the run the commands again> Which one? Nov 20, 2017 at 15:31
  • just clear the cache and check again. It should work Nov 20, 2017 at 15:32
  • But it works in the local environment as it is, without the changes you are suggesting. But not on staging. Why? Nov 20, 2017 at 15:38

Your Answer

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

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