Question

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;
    }

}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top