Table custom like this
I want get data from table " custom " by id in block magento 2. Please help me! Thanks all
UPDATE
I want get data by " custom_id "
UPDATE
function __construct
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Webkul\MpSellerMapLocator\Model\Mpsellermaplocator $mpSellerMapLocatorModel,
array $data = []
) {
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;
}
get data
$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;
Best Answer
Use load by Id to get data by id.
Try with below way.
Add below code in your block file.
In the above code, I inject class
\Namespace\ModuleName\Model\customTableFactory
in your case you have to inject your model class. and pass yourentity_id
in$id
That's it! I hope it helps.
Update:
You can also get data by another field like below.
And then you can use your variable directly in your code: