Php 安装过程中出错:di:compile-参数类型不兼容
我在运行安装程序时遇到以下错误:di:compile在我的magento 2中 不兼容的参数类型:必需的类型:\Magento\Catalog\Model\ProductTypes\ConfigInterface。实际类型:数组 不兼容的参数类型:必需的类型:\Magento\Wishlist\Model\WishlistFactory。实际类型:数组 导致该错误的代码如下Php 安装过程中出错:di:compile-参数类型不兼容,php,magento,magento2,Php,Magento,Magento2,我在运行安装程序时遇到以下错误:di:compile在我的magento 2中 不兼容的参数类型:必需的类型:\Magento\Catalog\Model\ProductTypes\ConfigInterface。实际类型:数组 不兼容的参数类型:必需的类型:\Magento\Wishlist\Model\WishlistFactory。实际类型:数组 导致该错误的代码如下 public function __construct( \Magento\Backend\Block\T
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
\Magento\GiftMessage\Model\Save $giftMessageSave,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Helper\Data $taxData,
\Magento\GiftMessage\Helper\Message $messageHelper,
StockRegistryInterface $stockRegistry,
StockStateInterface $stockState,
array $data = []
) {
$this->_messageHelper = $messageHelper;
$this->_wishlistFactory = $wishlistFactory;
$this->_giftMessageSave = $giftMessageSave;
$this->_taxConfig = $taxConfig;
$this->_taxData = $taxData;
$this->stockRegistry = $stockRegistry;
$this->stockState = $stockState;
parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
}
及
在我的布局中,我是这样打电话的
<block class="MyVendor\MyModule\Block\Adminhtml\Quote\Create\Items" template="Magento_Sales::order/create/items.phtml" name="items">
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid" template="Magento_Sales::quote/create/items/grid.phtml" name="items_grid">
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Coupons" template="Magento_Sales::order/create/form.phtml" name="coupons">
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Coupons\Form" template="Magento_Sales::order/create/coupons/form.phtml" name="form" />
</block>
</block>
</block>
提前感谢可能是个愚蠢的问题,但在执行命令之前是否清除了magento缓存
我在更新_构造时也遇到了问题,但在清除缓存时得到了修复。可能是个愚蠢的问题,但在执行命令之前是否清除了magento缓存
我在更新_构造时也遇到了问题,但在清除缓存时得到了修复。像这样保留构造函数函数
public function __construct(
\Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig
) {
$this->typeConfig = $typeConfig;
}
现在编译并检查将构造函数保持如下状态
public function __construct(
\Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig
) {
$this->typeConfig = $typeConfig;
}
现在编译并检查您需要将所有参数传递给其父构造函数,如下所示:
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
\Magento\GiftMessage\Model\Save $giftMessageSave,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Helper\Data $taxData,
\Magento\GiftMessage\Helper\Message $messageHelper,
StockRegistryInterface $stockRegistry,
StockStateInterface $stockState,
array $data = []
) {
$this->_messageHelper = $messageHelper;
$this->_wishlistFactory = $wishlistFactory;
$this->_giftMessageSave = $giftMessageSave;
$this->_taxConfig = $taxConfig;
$this->_taxData = $taxData;
$this->stockRegistry = $stockRegistry;
$this->stockState = $stockState;
//Pass All Arguments To Parent
parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $wishlistFactory, $giftMessageSave, $taxConfig, $taxData, $messageHelper, $stockRegistry, $stockState, $data);
}
如果仍然有错误,请告诉我。您需要将所有参数传递给其父构造函数,如下所示:
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
\Magento\GiftMessage\Model\Save $giftMessageSave,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Helper\Data $taxData,
\Magento\GiftMessage\Helper\Message $messageHelper,
StockRegistryInterface $stockRegistry,
StockStateInterface $stockState,
array $data = []
) {
$this->_messageHelper = $messageHelper;
$this->_wishlistFactory = $wishlistFactory;
$this->_giftMessageSave = $giftMessageSave;
$this->_taxConfig = $taxConfig;
$this->_taxData = $taxData;
$this->stockRegistry = $stockRegistry;
$this->stockState = $stockState;
//Pass All Arguments To Parent
parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $wishlistFactory, $giftMessageSave, $taxConfig, $taxData, $messageHelper, $stockRegistry, $stockState, $data);
}
如果仍然有错误,请告诉我。我想$typeConfig是您要添加到自己的类中的内容。 除了设置$this->typeConfig,还需要将所有变量传递到父类中 试试这个
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
\Magento\GiftMessage\Model\Save $giftMessageSave,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Helper\Data $taxData,
\Magento\GiftMessage\Helper\Message $messageHelper,
StockRegistryInterface $stockRegistry,
StockStateInterface $stockState,
array $data = [],
\Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig // your variable
) {
$this->typeConfig = $typeConfig; // your variable
parent::__construct(
$context,
$sessionQuote,
$orderCreate,
$priceCurrency,
$wishlistFactory,
$giftMessageSave,
$taxConfig,
$taxData,
$messageHelper,
$stockRegistry,
$stockState,
$data
);
}
我想$typeConfig是您想要添加到自己的类中的内容。 除了设置$this->typeConfig,还需要将所有变量传递到父类中 试试这个
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
\Magento\GiftMessage\Model\Save $giftMessageSave,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Helper\Data $taxData,
\Magento\GiftMessage\Helper\Message $messageHelper,
StockRegistryInterface $stockRegistry,
StockStateInterface $stockState,
array $data = [],
\Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig // your variable
) {
$this->typeConfig = $typeConfig; // your variable
parent::__construct(
$context,
$sessionQuote,
$orderCreate,
$priceCurrency,
$wishlistFactory,
$giftMessageSave,
$taxConfig,
$taxData,
$messageHelper,
$stockRegistry,
$stockState,
$data
);
}
错误消息不言自明:您键入了一个特定的类型/契约,但是当您调用方法/构造函数时,您提供了一个数组作为参数。您应该发布调用代码以提供一些上下文。错误消息本身就说明了这一点:您键入了某个类型/约定,但当您调用方法/构造函数时,您提供了一个数组作为参数。您应该发布调用代码以提供一些上下文。