安装过程中出错:di:compile - 不兼容的参数类型

时间:2017-02-14 13:59:07

标签: php magento magento2

我在运行安装程序时遇到以下错误:di:在我的magento 2中编译。

  

不兼容的参数类型:必需类型:\ Magento \ Catalog \ Model \ ProductTypes \ ConfigInterface。实际类型:数组;

     

不兼容的参数类型:必需类型:\ Magento \ Wishlist \ Model \ WishlistFactory。实际类型:数组;

负责错误的代码如下

    public function __construct(
    \Magento\Backend\Block\Context $context,
    \Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig,
    array $data = []
) {
    parent::__construct($context, $data);
    $this->typeConfig = $typeConfig;
}

并且

        <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>  

在我的布局中,我这样称呼

<!doctype html>
<html lang="da">
    <head>
        <title>Camera output</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/style.css" type="text/css" rel="stylesheet">
        <script src="jquery-3.1.1.min.js"></script>
    </head>
    <body>
        <video id="video" autoplay></video>
        <button id="snap" class="snapButton">Snap Photo</button>
        <canvas id="canvas" width="640" height="480"></canvas>

        <script src="js/script.js" type="text/javascript"></script>
    </body>
</html>

先谢谢

4 个答案:

答案 0 :(得分:0)

也许是一个愚蠢的问题但你在执行命令之前是否清除了magento缓存?

我在更新__construct时也遇到了问题,但在清除缓存时已修复。

答案 1 :(得分:0)

保持你的构造函数像这样

public function __construct(
    \Magento\Catalog\Model\ProductTypes\ConfigInterface $typeConfig
) {
    $this->typeConfig = $typeConfig;
}

现在编译并检查

答案 2 :(得分:0)

您需要将所有参数传递给其父构造函数,如下所示:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_main"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:orientation="vertical"
    android:padding="10dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <TextView
        android:id="@+id/date_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp"
        android:text="1st October 2017"
        android:textColor="@color/colorPrimary" />


    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorPrimary" />


    <TextView
        android:id="@+id/whats_left_for_today_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"

        android:text="Whats left for today"
        android:textColor="@color/colorPrimary" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/today_recycler_view_summary"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#eee"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp">

    </android.support.v7.widget.RecyclerView>

</LinearLayout>

<View
    android:id="@+id/clickable_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="@+id/linear_main"
    android:clickable="true"
    android:onClick="onTodayMainPageClick"
    app:layout_constraintLeft_toLeftOf="@+id/linear_main"
    app:layout_constraintRight_toRightOf="@+id/linear_main"
    app:layout_constraintTop_toTopOf="@+id/linear_main" />

如果您仍然有错误,请告诉我。

答案 3 :(得分:0)

我想$ typeConfig是你想要添加到你自己的类中的东西。 除了设置$ this-&gt; 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
    );
}