自定义管理网格在我的Magento 2应用中未显示任何数据

时间:2019-04-19 02:33:45

标签: magento2

当前,我正在创建一个新的自定义网格,以在管理面板中显示“客户”的特定属性(类似于“管理面板->客户->所有客户”中的网格,但仅显示客户ID,客户名称,电话,验证状态和许可证号)。

当我完成代码并重新加载页面后,网格不显示任何数据,而只显示了旋转的轮子。

verification statuslicense number是我通过UpgradeData.php添加到客户的自定义属性

我正在通过uicomponent创建自定义网格。我通读了本教程https://www.mageplaza.com/magento-2-module-development/create-admin-grid-magento-2.html,并利用Alan Storm Pestle.phar代码生成器生成了相关代码。

我的自定义管理网格设置为管理面板->客户->验证

以下文件是我的代码。我不知道哪一部分是错误的,并且会出错。

happyhackers / customer / etc / di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="happyhackers_customer_verification_data_source" xsi:type="string">Magento\Customer\Model\ResourceModel\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

happyhackers / customer / view / adminhtml / ui_component / happyhackers_customer_verification.xml

<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">happyhackers_customer_verification.happyhackers_customer_verification_data_source</item>
            <item name="deps" xsi:type="string">happyhackers_customer_verification.happyhackers_customer_verification_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">happyhackers_customer_verification_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string">Add New</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/Grid/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="happyhackers_customer_verification_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Happyhackers\Customer\Ui\Component\Listing\DataProviders\Happyhackers\Customer\Verification</argument>
            <argument name="name" xsi:type="string">happyhackers_customer_verification_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">entity_id</item>
                    </item>
                </item>
            </argument>
        </argument>
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
            </item>
        </argument>
    </dataSource>
    <listingToolbar name="listing_top">
        <settings>
            <sticky>true</sticky>
        </settings>
        <paging name="listing_paging"/>
        <filters name="listing_filters"/>
    </listingToolbar>
    <columns name="happyhackers_customer_verification_columns">
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">55</item>
                    <item name="indexField" xsi:type="string">entity_id</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="entity_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="sorting" xsi:type="string">asc</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                </item>
            </argument>
        </column>
        <column name="name">
            <settings>
                <filter>text</filter>
                <editor>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Name</label>
            </settings>
        </column>
        <column name="email">
            <settings>
                <filter>text</filter>
                <label translate="true">Email</label>
            </settings>
        </column>
        <column name="billing_telephone" sortOrder="60">
            <settings>
                <filter>text</filter>
                <label translate="true">Phone</label>
            </settings>
        </column>
        <column name="verification_status">
            <settings>
                <filter>text</filter>
                <editor>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Verification</label>
            </settings>
        </column>
        <actionsColumn name="actions" class="Happyhackers\Customer\Ui\Component\Listing\Column\Happyhackerscustomerverification\PageActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">107</item>
                    <item name="indexField" xsi:type="string">entity_id</item>
                    <item name="sortOrder" xsi:type="number">200</item>
                </item>
            </argument>
        </actionsColumn>
    </columns>
</listing>

Pestle.phar也会自动为我创建两个php文件,但是我不确定这是否会导致问题。

happyhackers / customer / Ui / Component / Listing / Column / Happyhackerscustomerverification / PageAction.php

<?php
namespace Happyhackers\Customer\Ui\Component\Listing\Column\Happyhackerscustomerverification;

class PageActions extends \Magento\Ui\Component\Listing\Columns\Column
{
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource["data"]["items"])) {
            foreach ($dataSource["data"]["items"] as & $item) {
                $name = $this->getData("name");
                $id = "X";
                if(isset($item["entity_id"]))
                {
                    $id = $item["entity_id"];
                }
                $item[$name]["view"] = [
                    "href"=>$this->getContext()->getUrl(
                        "happyhackers_customer_verification/grid/edit",["entity_id"=>$id]),
                    "label"=>__("Edit")
                ];
            }
        }

        return $dataSource;
    }    

}

Happyhackers /客户/ Ui /组件/列表/数据提供者/Happyhackers/Customer/Verification.php

<?php
namespace Happyhackers\Customer\Ui\Component\Listing\DataProviders\Happyhackers\Customer;

class Verification extends \Magento\Ui\DataProvider\AbstractDataProvider
{    
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        \Magento\Customer\Model\ResourceModel\Grid\CollectionFactory $collectionFactory,
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
        $this->collection = $collectionFactory->create();
    }
}

我希望在管理面板->客户->验证页面中,自定义网格会显示客户ID,客户名称,许可证编号,电话和验证状态。但实际上,它使我返回到内部服务器错误页面。

如果我注释掉di.xml中的内容,至少它将向我显示网格结构,但是在网格单元内什么也没有。

0 个答案:

没有答案