1

I tried to follow these tutorials:

But in both cases I ended up with a empty page. Without any grid!

This is my controller path: path/to/vendor/atty31/subscription/Controller/Adminhtml/Subscription/Index.php. This is my controller content:

<?php
namespace Atty31\Subscription\Controller\Adminhtml\Subscription;

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()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->prepend((__('View Subscriptions')));

        return $resultPage;
    }

    protected function _isAllowed()
    {
        return $this->_authorization->isAllowed('Atty31_Subscription::subscription_index');
    }
} 

This is my di.xml path: path/to/vendor/atty31/subscription/etc/di.xml and it's content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Atty31\Subscription\Model\ResourceModel\Subscription\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">atty31_subscription</argument>
            <argument name="resourceModel" xsi:type="string">Atty31\Subscription\Model\ResourceModel\Subscription</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="atty31_subscription_grid_data_source" xsi:type="string">Atty31\Subscription\Model\ResourceModel\Subscription\Collection</item>
            </argument>
        </arguments>
    </type>
</config>

and the layout xml path: /path/to/vendor/atty31/subscription/view/adminhtml/layout/subscription_subscription_index.xml and it's content:

<?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">
            <uiComponent name="atty31_subscription_grid"/>
        </referenceContainer>
    </body>
</page>

and finally the ui component file's path: path/to/vendor/atty31/subscription/view/adminhtml/ui_component/atty31_subscription_grid.xml and it's content:

<?xml version="1.0" encoding="UTF-8"?>
<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">atty31_subscription_grid.atty31_subscription_grid_data_source</item>
            <item name="deps" xsi:type="string">atty31_subscription_grid.atty31_subscription_grid_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">atty31_subscription_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" translate="true">Add New Blog</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="atty31_subscription_grid_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
            <argument name="name" xsi:type="string">atty31_subscription_grid_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">blog_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="atty31_subscription_columns">
        <!--The list of columns-->
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">id</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="sorting" xsi:type="string">asc</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                </item>
            </argument>
        </column>
        <column name="customer_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="sorting" xsi:type="string">asc</item>
                    <item name="label" xsi:type="string" translate="true">Customer ID</item>
                </item>
            </argument>
        </column>
        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                    <item name="dataType" xsi:type="string">date</item>
                    <item name="label" xsi:type="string" translate="true">Created At</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Does anybody give some hints what should i check next? or maybe point me to the mistake that i made ?

Thank you in advance!

[UPDATE] I've added my routes.xml file content:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="admin">
        <route id="subscriptions" frontName="subscriptions">
            <module name="Atty31_Subscription" />
        </route>
    </router>
</config>
1

As per my observation (from tutorial you followed), You given front name atty31_subscription in routes.xml.

So you need to change your xml file name from:

subscription_subscription_index.xml

to

atty31_subscription_subscription_index.xml

which is located at: path/to/vendor/Atty31/Subscription/view/adminhtml/layout/atty31_subscription_subscription_index.xml

I just tried your code and after change file name, all works fine :)

Edit I

In other words, XML file name should be:

FrontName_ControllerFolder_ControllerName.xml
  • Actually my frontname is: subscriptions, so if i changed my layput xml file name, like: subscriptions_subscription_index.xml , it works :) . Thnx for pointing me to the right direction :) . If you can update your post with this info, will be a good reference for others, as well. – Attila Naghi Oct 13 at 10:52
  • @AttilaNaghi, Updated :) – Pawan Oct 13 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.