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.
<?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);
}
Best Answer
Simply clear the cache:
For Magento 2.1.x
For Magento 2.2.x