Сетка администратора с использованием макета, не отображающего содержимое в magento 2 - PullRequest
0 голосов
/ 25 сентября 2018

Выпуск:

enter image description here

Я разместил

Drc \ Manufacturingmatch \ etc \ di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="drc_manufacturingmatch_credit_listing_data_source" xsi:type="string">Drc\Manufacturingmatch\Model\ResourceModel\Credits\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="Drc\Manufacturingmatch\Model\ResourceModel\Credits\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">infi_creditstransaction</argument>
            <argument name="resourceModel" xsi:type="string">Drc\Manufacturingmatch\Model\ResourceModel\Credits</argument>
        </arguments>
    </virtualType>
</config>

Drc \ Manufacturingmatch \ Controller \ Adminhtml \ Credit \ Index.php

<?php 

namespace Drc\Manufacturingmatch\Controller\Adminhtml\Credit;  

class Index extends \Magento\Backend\App\Action { 

    protected $resultPageFactory = false;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    )
    {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {

        echo 'hererer';
        die;
        // $resultPage = $this->resultPageFactory->create();

        // return $resultPage;

        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend((__('Credit Transactions')));
        $resultPage->setActiveMenu('Learning_Test::test');
        $resultPage->addBreadcrumb(__('Test'), __('Test'));
        $resultPage->addBreadcrumb(__('Manage Test'), __('Manage Test'));

        // $resultPage->addContent(
        //     $resultPage->getLayout()->createBlock('Drc\Manufacturingmatch\Block\Adminhtml\Credit')
        // );
        return $resultPage;
    }
}

Drc \ Manufacturingmatch \ Block \ Adminhtml \ Credit \Index.php

class Index extends \Magento\Backend\Block\Widget\Grid\Container
{
     protected function _construct()
    {
        $this->_controller = 'credit_index';
        $this->_blockGroup = 'Drc_Manufacturingmatch';
        $this->_headerText = __('Credit Transactions');
        $this->_addButtonLabel = __('Create New Post');
        parent::_construct();
    }
}

Drc \ Manufacturingmatch \ view \ adminhtml \ layout \ drc_manufacturingmatch_credit_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="styles"/>
    <body>
        <referenceContainer name="content">
            <block class="Drc\Manufacturingmatch\Block\Adminhtml\Credit" name="credit_index">
                <block class="Magento\Backend\Block\Widget\Grid" name="credit_index.grid" as="grid">
                    <arguments>
                        <argument name="id" xsi:type="string">post_id</argument>
                        <argument name="dataSource" xsi:type="object">Drc\Manufacturingmatch\Model\ResourceModel\Credits\Collection</argument>
                        <argument name="default_sort" xsi:type="string">id</argument>
                        <argument name="default_dir" xsi:type="string">DESC</argument>
                        <argument name="save_parameters_in_session" xsi:type="string">1</argument>
                    </arguments>
                    <block class="Magento\Backend\Block\Widget\Grid\ColumnSet" name="credit_index.grid.columnSet" as="grid.columnSet">
                        <arguments>
                            <argument name="rowUrl" xsi:type="array">
                                <item name="path" xsi:type="string">*/*/edit</item>
                            </argument>
                        </arguments>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="id">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">ID</argument>
                                <argument name="index" xsi:type="string">id</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="credit">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Credit</argument>
                                <argument name="index" xsi:type="string">credit</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="debit">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Debit</argument>
                                <argument name="index" xsi:type="string">debit</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="balance">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Balance</argument>
                                <argument name="index" xsi:type="string">balance</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                    </block>
                </block>
            </block>
        </referenceContainer>
    </body>
</page>
...