6

I get the following when using my controller through a front end route.

Fatal error: Uncaught TypeError: Argument 1 passed to Namespace\Module\Controller\Index\Index::__construct() must be an instance of Magento\Framework\App\Action\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in /website-magento-2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in /Projects/Work/website-magento-2/app/code/Namespace/Module/Controller/Index/index.php:45 Stack trace: #0 //Projects/Work/website-magento-2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): Namespace\Module\Controller\Index\Index->__construct(Object(Magento\Framework\ObjectManager\ObjectManager))

#1 /Projects/Work/website-magento-2/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Namespace\Module...', Array) #2 /Projects/Work/website-magento-2/vendor/magento/framework/ObjectManager/ObjectManager. in /Projects/Work/website-magento-2/app/code/Namespace/Module/Controller/Index/index.php on line 45

Controller construct

public function __construct(
        Context $context,
        PageFactory $resultPageFactory,
        Customer $customer,
        CustomerSession $customerSession,
        Session $catalogSession
    ){
        $this->resultPageFactory = $resultPageFactory;
        $this->context = $context;
        $this->customer = $customer;
        $this->customerSession = $customerSession;
        $this->catalogSession = $catalogSession;

        parent::__construct($context);

    }

I have seen posts about this issue and the resolution is that I delete and regenerate var/di, createCharge, var/cache. However this isn't working.

6
  • Try running bin/magento setup:upgrade followed by bin/magento cache:flush. Commented Jan 27, 2017 at 1:50
  • can you clear the cache?
    – Bhavik
    Commented Jan 27, 2017 at 4:27
  • please provide class definition on your code, may be then i will help u
    – Bhavik
    Commented Jan 27, 2017 at 4:28
  • could you show your full controller file Commented Jan 27, 2017 at 5:47
  • Delete var/generation folder
    – Priyank
    Commented Jan 27, 2017 at 6:06

2 Answers 2

10

I have had this type of error as well. It was a spelling problem, I called to instantiate an object but used a lower case letter in the class name when I should have used an upper case letter.

See also this answer: https://magento.stackexchange.com/a/164924/24432

5

I had this problem as well. Similar to the above I was using lowercase in my file names ie "index.php". I changed it to "Index.php" (default controller), recompiled, and it worked.

MacOS, Apache, PHP7

1
  • it is work for me gret Commented Nov 24, 2017 at 10:40

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.