سؤال

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);
    }
هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top