2

I am creating a custom module to show some listing data submitted from frontend to database after save to show it in admin GRID. Saving data is working fine but listing in GRID using ui_component is not working.

Changed the router and menu file a bit and now i am getting this error on the page in admin where grid is.

Exception #0 (Exception): Warning: class_implements(): Class ListsGridDataProvider does not exist.

my Controller in Company\Module\Controller\Adminthtml\Testimonial

<?php

namespace Apriljune\Testimonial\Controller\Adminhtml\Testimonial;

class Testimonial 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((__('Testimonial')));

    return $resultPage;
}

protected function _isAllowed()
{
    return true;
}

}

My router is

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="apriljune_testimonial" frontName="apriljune_testimonial">
  <module name="Apriljune_Testimonial" before="Magento_Backend" />
</route>
</router>
</config>

my menu.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
    <add id="Apriljune_Testimonial::testimonial" title="Apriljune Testimonial" resource="Apriljune_Testimonial::testimonial" module="Apriljune_Testimonial"  sortOrder="20"/>
    
    <add id="Apriljune_Testimonial::testimoniallist" title="Testimonial List" resource="Apriljune_Testimonial::apriljune_testimonial_testimonial" parent="Apriljune_Testimonial::testimonial" action="apriljune_testimonial/testimonial/testimonial" module="Apriljune_Testimonial" sortOrder="20"/>
 </menu>
  </config>

Model is:

<?php

 namespace Apriljune\Testimonial\Model;

 use Magento\Framework\Model\AbstractModel;

 class Testimonial extends \Magento\Framework\Model\AbstractModel {


 protected function _construct() {
    $this->_init('Apriljune\Testimonial\Model\ResourceModel\Testimonial');
  }

}

Resource Model:

<?php

 namespace Apriljune\Testimonial\Model\ResourceModel;

 use Magento\Framework\Model\ResourceModel\Db\AbstractDb;

 class Testimonial extends AbstractDb
 {

public function __construct(
    \Magento\Framework\Model\ResourceModel\Db\Context $context
)
{
    parent::__construct($context);
}

/**
 * Initialize resource model
 *
 * @return void
 */
protected function _construct()
{
    $this->_init('apriljune_testimonial', 'id');
}
}

Collection File in Apriljune\Testimonial\Model\ResourceModel\Testimonial

<?php

namespace Apriljune\Testimonial\Model\ResourceModel\Testimonial;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Apriljune\Testimonial\Model\Testimonial as Model;
use Apriljune\Testimonial\Model\ResourceModel\Testimonial as ResourceModel;

class Collection extends AbstractCollection{

protected $_idFieldName = 'id';
protected $_eventPrefix = 'apriljune_testimonial_testimonial_collection';
protected $_eventObject = 'testimonial_collection';

protected function _construct()
{
    $this->_init(Model::class, ResourceModel::class);
}
}

my di.xml file is like:

<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="apriljune_testimonial_testimonial_listing_data_source" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection</item>
        </argument>
    </arguments>
</type>
<virtualType name="Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
    <arguments>
        <argument name="mainTable" xsi:type="string">apriljune_testimonial</argument>
        <argument name="resourceModel" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial</argument>
    </arguments>
</virtualType>

admin layout file for declaring ui_component like follows:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
    <referenceContainer name="content">
        <uiComponent name="apriljune_testimonial_testimonial_listing"/>
    </referenceContainer>
</body>

ui_component have the following code in it,

<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">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source</item>
        <item name="deps" xsi:type="string">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_data_source</item>
    </item>
    <item name="spinner" xsi:type="string">spinner_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 Testimonial</item>
            <item name="class" xsi:type="string">primary</item>
            <item name="url" xsi:type="string">*/*/new</item>
        </item>
    </item>
</argument>
<dataSource name="apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_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">apriljune_testimonial_testimonial_listing.apriljune_testimonial_testimonial_listing_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">id</item>
                </item>
            </item>
        </argument>
    </argument>
</dataSource>
<columns name="spinner_columns">
    <selectionsColumn name="id">
        <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">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">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="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</item>
            </item>
        </argument>
    </column>
    <column name="modified_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">Modified</item>
            </item>
        </argument>
    </column>
</columns>
</listing>

and DB schema i am using is declarative one like this:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

<table name="apriljune_testimonial" resource="default" comment="Table for Apriljune Testimonial Main">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="status" nullable="false"/>
    <column xsi:type="date" name="created_at"  nullable="false"/>
    <column xsi:type="date" name="modified_at"  nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
</table>

<table name="apriljune_testimonial_author" resource="default" comment="Table for Apriljune Testimonial Author">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Constraint"/>
    <column xsi:type="varchar" name="author_name" nullable="false"/>
    <column xsi:type="varchar" name="author_email" nullable="false"/>
    <column xsi:type="varchar" name="author_company" nullable="false"/>
    <column xsi:type="varchar" name="author_job_title" nullable="false"/>
    <column xsi:type="varchar" name="author_city"  nullable="false"/>
    <column xsi:type="varchar" name="author_image" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_AUTHOR_TESTIMONIAL_ID"
                table="apriljune_testimonial_author" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

<table name="apriljune_testimonial_social" resource="default"
       comment="Table for Apriljune Testimonial Social Profile Information">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Constraint"/>
    <column xsi:type="varchar" name="facebook_url" nullable="false"/>
    <column xsi:type="varchar" name="linkedin_url" nullable="false"/>
    <column xsi:type="varchar" name="twitter_url" nullable="false"/>
    <column xsi:type="varchar" name="youtu_url" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_SOCIAL_TESTIMONIAL_ID"
                table="apriljune_testimonial_social" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

<table name="apriljune_testimonial_content" resource="default" comment="Table for Apriljune Testimonial Content">
    <column xsi:type="int" name="id" identity="true" comment="Column Auto Increment" unsigned="true"
            nullable="false"/>
    <column xsi:type="int" name="testimonial_id" comment="Foreign Key Id from Author Table"/>
    <column xsi:type="varchar" name="testimonial_title" nullable="false"/>
    <column xsi:type="varchar" name="testimonial_description" nullable="false"/>
    <column xsi:type="varchar" name="testimonial_rating_number" nullable="false"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id"/>
    </constraint>
    <constraint xsi:type="foreign"
                referenceId="APRILJUNE_TESTIMONIAL_ID_APRILJUNE_TESTIMONIAL_CONTENT_TESTIMONIAL_ID"
                table="apriljune_testimonial_content" column="id"
                referenceTable="apriljune_testimonial" referenceColumn="id"/>
</table>

</schema>

as i have said above frontend form submission is really working fine and saving the data into multiple tables , but i am facing an issue with the admin data it is still showing me the blank page no grid is creating but just showing the Title there, please have a look at the code provided and identify the mistakes or any possible solution.

Thanks in advance.

Screenshot: enter image description here

1 Answer 1

1

you can try with below code in your di.xml file:

di.xml

<!-- Create our type GridDataProvider -->
      <virtualType name="TestimonialGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
            <arguments>
                <argument name="collection" xsi:type="object" shared="false">Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection</argument>
                <argument name="filterPool" xsi:type="object" shared="false">TestimonialGridFilterPool</argument>
            </arguments>
     </virtualType>
        
     <virtualType name="TestimonialGridFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
            <arguments>
                <argument name="appliers" xsi:type="array">
                    <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                    <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
                </argument>
            </arguments>
     </virtualType>

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="apriljune_testimonial_testimonial_listing_data_source" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">apriljune_testimonial</argument>
            <argument name="resourceModel" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial</argument>
        </arguments>
    </virtualType>
5
  • Still is the same error for the ListsGridDataProvider , i have updated the di.xml file with your code and then run the di compile again by clearing content and setup:upgrade Jul 16, 2020 at 8:48
  • can you please deploy also Jul 16, 2020 at 9:13
  • Yeah thats fine now, but in Grid it keep spinning and loading the data in columns here is the screenshot:prnt.sc/tiuq0w Jul 16, 2020 at 10:03
  • thanks for this, it is all working fine now, this post gave me a hint as well.magento.stackexchange.com/questions/286551/… Jul 16, 2020 at 11:02
  • @shoaibMunir, please upvote so that it is useful for other people also. Jul 16, 2020 at 11:11

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.