magento 2 How to get my custom table data ? To get custom table data we have to use custom module.
First of all need to created Model and Collection file associated with that tables.
As a second step, We need to add Block PHP file and inject model factory class into constructor as below.
Now 3rd step we need to Prepare a public method in your block to access collection like below code.
Now, you need to call $this->getCollectionData() in phtml will return collection. you can use in loop.
Thank You.!
First of all need to created Model and Collection file associated with that tables.
As a second step, We need to add Block PHP file and inject model factory class into constructor as below.
public function __construct(
Context $context,
\Namespace\Modulename\Model\ModelNameFactory $modelNameFactory,
array $data = array()
) {
$this->_modelFactory = $modelFactory;
parent::__construct($context, $data);
}
Now 3rd step we need to Prepare a public method in your block to access collection like below code.
public function getCollectionData(){
return $this->_modelFactory->create()->getCollection();
}
Now, you need to call $this->getCollectionData() in phtml will return collection. you can use in loop.
Thank You.!
Comments
Post a Comment