6

I am getting "Uncaught ArgumentCountError: Too few arguments to function on parent::__construct($context);

Index.php

<?php

namespace MyTheme\Theme\Controller\Index;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class Index extends \Magento\Framework\App\Action\Action
{   
    /**
    * @var \Magento\Framework\View\Result\PageFactory
    */
    protected $resultPageFactory;

    public function __construct(Context $context, PageFactory $pageFactory)
    {
        parent::__construct($context);
        $this->resultPageFactory = $pageFactory;
    }

    public function execute()
    {
        $result = $this->resultPageFactory->create();
        return $result;
    }
}

Even if I use parent::__construct($context, $pageFactory); instead of parent::__construct($context); I get the same error.

  • Should remove the '\'. – Khoa TruongDinh Oct 26 '17 at 13:19
  • @KhoaTruongDinh from where? – brazuka Oct 26 '17 at 13:30
  • Remove the '\' from use after namespace – Suresh Chikani Oct 26 '17 at 13:32
  • @SureshChikani I remove the '\' but I still get the same error. I just updated the code. – brazuka Oct 26 '17 at 13:36
  • 1
    Just run one time upgrade command it will be solved – Ansar Husain Sep 20 '18 at 5:05
9

After a couple hours I found a solution. I had to run the commands below:

  1. php bin/magento cache:flush
  2. php bin/magento cache:clean
  3. php bin/magento setup:upgrade
  4. bin/magento setup:di:compile
  5. From magento root directory: chmod -R 777 var/*
| improve this answer | |
  • Why would like to make each file in var/ executable? Better use find -type d chmod 777 {} \; – Alex Jan 8 '19 at 13:23
6

It means that a old function signature is still cached. If you are during development,

php bin/magento deploy:mode:set developer

might be enough. Otherwise brazuka's answer would help.

| improve this answer | |
1

Follow the following steps:

1. From magento root directory: chmod -R 777 var/ generated/

2. From magento root directory: rm -rf generated/code/MyTheme

Reason:

There might be already generated Interceptor class, then you pass additional dependency injection to the constructor.The interceptor class is not rewrite properly.

| improve this answer | |

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.