1

Created a module which was working for a long time, however after some other edits to the site I got this error:

"Recoverable Error: Argument 1 passed to vendor\module\Controller\Cart\Index::__construct() must be an instance of Magento\Framework\App\Action\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in /Applications/MAMP/htdocs/project/shop/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in /Applications/MAMP/htdocs/project/shop/app/code/vendor/module/Controller/Cart/index.php on line 14"

Removing var/generation, var/di and var/cache folders solve the problem, however, it reappears after setup:di:compile

Any thoughts on possible fixes?

Here is the controller code:

<?php
namespace vendor\module\Controller\Cart;




class Index extends \Magento\Framework\App\Action\Action {

    /** @var  \Magento\Framework\View\Result\Page */
    protected $resultPageFactory;


    /**      * @param \Magento\Framework\App\Action\Context $context      */
    public function __construct(\Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory)     {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * Blog Index, shows a list of recent blog posts.
     *
     * @return \Magento\Framework\View\Result\PageFactory
     */
    public function execute()
    {
      header('Content-Type:text/plain');
      header("Access-Control-Allow-Origin: *");
      $resultPage = $this->resultPageFactory->create();
      return $resultPage;
    }

}
  • This error may occur due to use of case sensitive name in controller or your module. This type of error only generate after compilation. If possible write your code how your controller is calling, it will help for find exact possible reason. – Yogesh Karodiya May 23 '17 at 8:45
  • Legend! checked all class names etc beforehand, but didn't check the filename, it was called index instead of Index. problem solved! – perrivdb May 23 '17 at 10:27
  • If answer is helpful for you then accept answer that can can help for others. – Yogesh Karodiya May 23 '17 at 10:44
1

This error may occur due to use of case sensitive name in controller or module. Generally this error ignore without the code compilation. This type of error only generate after compilation. It seems that in your code:

shop/app/code/vendor/module/Controller/Cart/index.php

You used i instead of I.

  • Also comes if when lower case class written in namespace. – Amit Singh May 23 '17 at 10:47

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.