为什么我不能在Magento 2中注入ProductRepositoryInterface?
我有一个控制器动作,我想将产品存储库注入其中 namespace Nosto\Tagging\Controller\Export; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Backend\App\Action; use Magento\Framework\App\Action\Context; class Test extends Action { private $_productRepository; public function __construct( Context $context, StoreManagerInterface $storeManager, ProductRepositoryInterface $productRepository ) { parent::__construct($context); $this->_storeManager = $storeManager; $this->_productRepository = $productRepository; } 无论我以什么顺序放置构造函数参数,Magento的依赖项注入总是为该productRepository参数注入一个无效的类,从而导致PHP抛出和参数错误。该storeManagerGETD注射就好了。清除缓存没有帮助。 这是引发的异常: Recoverable Error: Argument 3 passed to Nosto\Tagging\Controller\Export\Test::__construct() must implement interface Magento\Catalog\Api\ProductRepositoryInterface, …