How to Display Table Data in Magento 2
Commonly you want to get table information from Magento 2 data set to redo Magento 2 store as per your necessities in this way we will make sense of how might you bring table information From Data set in Magento 2. By utilizing this technique you can get information from any table here you can see that we are bringing client table information from Magento 2 data set utilizing the custom module and show on the frontend.
Stage 1: You really want to make a fundamental module. you can follow this connection given beneath to make a Magento 2 module. Here is the seller name and the module is FetchTableData
Stage 2: Presently in the wake of making the fundamental module of Magento 2 you really want to make a course document and add this code given underneath
application/code//FetchTableData/and so on/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-occasion" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/and so forth/routes.xsd">
<switch id="standard">
<course frontName="fetchdata" id="fetchdata">
<module name="_FetchTableData"/>
</route>
</router>
</config>
Stage 3: Make a regulator and activity document way
application/code//FetchTableData/Regulator/Record/Index.php
add this code given beneath in this document
<?php
namespace\FetchTableData\Controller\Index;
class Record broadens \Magento\Framework\App\Action\Action
{
safeguarded $_pageFactory;
public capability __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public capability execute()
{
return $this->_pageFactory->create();
}
}
Stage 4: Make a format record fetchdata_index_index.xml
application/code//FetchTableData/view/frontend/format/fetchdata_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-occasion" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Design/and so forth/page_configuration.xsd">
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="fetchdata_index_index" template="_FetchTableData::fetchtabledata.phtml"/>
</referenceContainer>
</page>
Stage 5: Make a format document fetchtabledata.phtml
application/code/FetchTableData/view/frontend/formats/fetchtabledata.phtml
<?php
$this->_resources = \Magento\Framework\App\ObjectManager::getInstance()- >get('Magento\Framework\App\ResourceConnection');
$connection= $this->_resources->getConnection();
$dataTable = $this->_resources->getTableName('customer_entity');
$sql = "select * from " . $dataTable;
$customersData = $connection->fetchAll($sql);
foreach ($customersData as $key => $customer) {
print_r($customer) . "</br>";
}
?>
Stage 6: Run this following Comman
php container/magento setup:upgrade
php container/magento setup:di:compile
php container/magento setup:static-content:deploy - f en_US
php container/magento cache:flush
php container/magento cache:clean
php container/magento indexer:reindex
Stage 7: Really look at result on frontend
References:
Comments
Post a Comment