0

I have created a controller that uses the orderfactory because i need to load and modify a order.

The class looks like this:

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

    protected $_myFactory;
    protected $_orderFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Bla\Blabla\Model\myFactory $myFactory,
        \Magento\Sales\Model\OrderFactory $orderFactory)
    {
        parent::__construct($context);
        $this->_myFactory = $myFactory;
        $this->_orderFactory = $orderFactory;
    }

    public function execute() {
       //some code
    }
}

Upon using this controller i get the following error:

Argument 3 passed to Bla\Blabla\Controller\Callback\Accept::__construct() must be an instance of Magento\Sales\Model\OrderFactory, none given

It worked at a start then it just refused to inject the factory. Can anyone see a problem with my code? I am going nuts over this.

  • 1
    Have you deleted var/di and var/generation ? – MauroNigrele Feb 4 '16 at 9:21
  • Solved it @MauroNigrele, one never tries the most simple thing until someone suggests it. Thanks! – nenne Feb 4 '16 at 9:24
  • Cool rm -rf seems to be the magento2 dev best friend :) I've created an answer for your question, could be useful for someone else. – MauroNigrele Feb 4 '16 at 9:32
2

Try this:

  • remove [magento_root]/var/cache
  • remove [magento_root]/var/di
  • remove [magento_root]/var/generation

If you are working on PHP >= 5.5 check if op_cache is disabled if not restart PHP should clean the opcode cache.

Btw I'm assuming you have magento as developer mode

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.