Tôi có một hành động điều khiển mà tôi muốn tiêm kho lưu trữ sản phẩm
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;
}
Bất kể thứ tự nào tôi đặt các đối số hàm tạo của mình, phép tiêm phụ thuộc của Magento luôn tiêm một lớp không hợp lệ cho productRepositoryđối số khiến PHP ném và lỗi đối số. Các storeManagergetd tiêm tốt. Xóa bộ nhớ cache không giúp được gì.
Đây là ngoại lệ được ném:
Recoverable Error: Argument 3 passed to Nosto\Tagging\Controller\Export\Test::__construct() must implement interface Magento\Catalog\Api\ProductRepositoryInterface, instance of Nosto\Tagging\Helper\Account given.
Tên lớp và vị trí đối số trong thông báo lỗi thay đổi nhưng định nghĩa lỗi luôn giống nhau. Loại bỏ ProductRepositoryInterfacekhỏi hàm tạo làm cho mọi thứ trở lại tốt đẹp.