2

I have added model in my constructor

public function __construct(
    Context $context,
    PageFactory $resultPageFactory,
    \Vendor\Module\Model\Productsgrid $model
)
{
    $this->model = $model;
    $this->resultPageFactory = $resultPageFactory;
    return parent::__construct($context);
}

After adding model I am getting this error:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function...

When I am removing Productsgrid model it's working fine, am I doing something wrong?

3
  • have you run upgrade command one time ? Feb 14, 2019 at 11:55
  • 1
    Whenever you change something in constructor, you need to remove generated folder of magento. You can use 'rm -rf generated/*' to overcome this whenever you change constructor arguments.
    – Yash Shah
    Feb 14, 2019 at 11:58
  • 1
    Please remove generated/ and php bin/magento cache:clean then it will work, no need of upgrade or deploying stuffs. Feb 14, 2019 at 11:58

1 Answer 1

1

This happens with me before. You need to run upgrade dicompile and full deployment script

php -dmemory_limit=1G bin/magento setup:upgrade
php -dmemory_limit=1G bin/magento setup:di:compile
php bin/magento deploy:mode:set developer --skip-compilation
php bin/magento setup:static-content:deploy --theme Magento/backend -f
php bin/magento setup:static-content:deploy --theme Naheed/NaheedTheme -f
php bin/magento cache:clean

This will resolve your issue

1
  • @divyasekar I will try Feb 14, 2019 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.