0

I have faced this issue many times, but unable to understand why? what is the (logic/concept/approach) behind injecting any object. i have injected few parameter to my save controller, before adding the 4th parameter it was working fine, just after adding $file error occur.

can anyone simplify understanding of dependency injection. what all we can inject and why his fatal error comes.

enter image description here

<?php

namespace AB\Tester\Controller\Adminhtml\Slide;

use Magento\Backend\App\Action;
use Magento\MediaStorage\Model\File\UploaderFactory;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Driver\File;
class Save extends Action{

    protected $_mediaDirectory;
    protected $_fileUploaderFactory;
    protected $_newFileName;
    protected $_slidesFolderPath;
    protected $_file;


    /**
     * Save constructor.
     * @param Action\Context $context
     */
    public function __construct(
        Action\Context $context,
        Filesystem $fileSystem,
        UploaderFactory $uploaderFactory,
        File $file
    )
    {
        /** @var TYPE_NAME $filesystem */
        $this->_mediaDirectory = $fileSystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
        $this->_fileUploaderFactory = $uploaderFactory;
        $this->_slidesFolderPath = "AB_Tester/";
        $this->_file = $file;
        parent::__construct($context);
    }
0

Simply clear the cache:

cd /path/to/magento2
rm -rf var/cache/ var/page_cache/

For Magento 2.1.x

rm -rf var/generation/

For Magento 2.2.x

rm -rf generated/code
rm -rf generated/metadata
2
  • Thanks, now i understand if such problem comes so need to delete generate folder. issue resolved.
    – Nits
    Jul 31 '18 at 15:23
  • If that solves your problem then please accept the answer.
    – MagePsycho
    Jul 31 '18 at 15:29

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.