How to get data from custom table by entity_id for custom table in magento 2?Join from custom table to customer_entity table and get all data customer in Magento 2Unit Test for overwrite collection class in magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Set custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2.1 Create a filter in the product grid by new attributeHow to access model in bundle block class?Data from Controller to ViewI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2 How to upgrade existing custom customer address attribute?

Why is gun control associated with the socially liberal Democratic party?

Why not make one big cpu core?

Does "aurea" have the second meaning?

What does this circuit symbol mean?

New Site Design!

What is the theme of analysis?

Is it possible to have battery technology that can't be duplicated?

What do I need to do, tax-wise, for a sudden windfall?

Short story about psychologist analyzing demon

Should I worry about having my credit pulled multiple times while car shopping?

How can I detect if I'm in a subshell?

How to represent jealousy in a cute way?

Why does this Apple //e drops into system monitor when booting?

How can I find out about the game world without meta-influencing it?

Can an escape pod land on Earth from orbit and not be immediately detected?

Why is it bad to use your whole foot in rock climbing

Is there a term for someone whose preferred policies are a mix of Left and Right?

What does the "titan" monster tag mean?

Parsing text written the millitext font

Will users know a CardView is clickable

Arrows inside a commutative diagram using tikzcd

In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?

Can a 40amp breaker be used safely and without issue with a 40amp device on 6AWG wire?

Does every chapter have to "blow the reader away" so to speak?



How to get data from custom table by entity_id for custom table in magento 2?


Join from custom table to customer_entity table and get all data customer in Magento 2Unit Test for overwrite collection class in magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Set custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2.1 Create a filter in the product grid by new attributeHow to access model in bundle block class?Data from Controller to ViewI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2 How to upgrade existing custom customer address attribute?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Table custom like this



enter image description here



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 "



enter image description here



UPDATE



function __construct



public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelMpsellermaplocator $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;









share|improve this question



















  • 1





    mageplaza.com/magento-2-module-development/… this can help you.

    – Rizwan Khan
    Jun 7 at 4:33











  • Name field coming from join or name is the field of your custom table?

    – Amit Bera
    Jun 7 at 4:39

















1















Table custom like this



enter image description here



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 "



enter image description here



UPDATE



function __construct



public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelMpsellermaplocator $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;









share|improve this question



















  • 1





    mageplaza.com/magento-2-module-development/… this can help you.

    – Rizwan Khan
    Jun 7 at 4:33











  • Name field coming from join or name is the field of your custom table?

    – Amit Bera
    Jun 7 at 4:39













1












1








1


1






Table custom like this



enter image description here



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 "



enter image description here



UPDATE



function __construct



public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelMpsellermaplocator $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;









share|improve this question
















Table custom like this



enter image description here



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 "



enter image description here



UPDATE



function __construct



public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelMpsellermaplocator $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;






magento2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 7 at 5:03







TN98

















asked Jun 7 at 4:29









TN98TN98

12410




12410







  • 1





    mageplaza.com/magento-2-module-development/… this can help you.

    – Rizwan Khan
    Jun 7 at 4:33











  • Name field coming from join or name is the field of your custom table?

    – Amit Bera
    Jun 7 at 4:39












  • 1





    mageplaza.com/magento-2-module-development/… this can help you.

    – Rizwan Khan
    Jun 7 at 4:33











  • Name field coming from join or name is the field of your custom table?

    – Amit Bera
    Jun 7 at 4:39







1




1





mageplaza.com/magento-2-module-development/… this can help you.

– Rizwan Khan
Jun 7 at 4:33





mageplaza.com/magento-2-module-development/… this can help you.

– Rizwan Khan
Jun 7 at 4:33













Name field coming from join or name is the field of your custom table?

– Amit Bera
Jun 7 at 4:39





Name field coming from join or name is the field of your custom table?

– Amit Bera
Jun 7 at 4:39










1 Answer
1






active

oldest

votes


















2














Use load by Id to get data by id.



Try with below way.



Add below code in your block file.



<?php
namespace TestModuleBlock;

class TestBlock extends MagentoFrameworkViewElementTemplate


protected $customTable;


public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
NamespaceModuleNameModelcustomTableFactory $customTable

)


$this->customTable = $customTable;
parent::__construct($context);

public function getLoadProduct($id)

return $this->customTable->create()->load($id);





In the above code, I inject class NamespaceModuleNameModelcustomTableFactory in your case you have to inject your model class. and pass your entity_id in $id



That's it! I hope it helps.




Update:



You can also get data by another field like below.



protected $customTablecollection;

public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelResourceModelMpsellermaplocatorcollection $mpSellerMapLocatorModel,
array $data = []
)
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;



And then you can use your variable directly in your code:



$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;





share|improve this answer

























  • can you get it by name ?

    – TN98
    Jun 7 at 4:40











  • Yes you can get it by name also but you have to use another methode.

    – Chirag Patel
    Jun 7 at 4:41











  • can you help me ? :(((

    – TN98
    Jun 7 at 4:42











  • Check my updated answer :)

    – Chirag Patel
    Jun 7 at 4:45











  • Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

    – TN98
    Jun 7 at 4:55












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277547%2fhow-to-get-data-from-custom-table-by-entity-id-for-custom-table-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use load by Id to get data by id.



Try with below way.



Add below code in your block file.



<?php
namespace TestModuleBlock;

class TestBlock extends MagentoFrameworkViewElementTemplate


protected $customTable;


public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
NamespaceModuleNameModelcustomTableFactory $customTable

)


$this->customTable = $customTable;
parent::__construct($context);

public function getLoadProduct($id)

return $this->customTable->create()->load($id);





In the above code, I inject class NamespaceModuleNameModelcustomTableFactory in your case you have to inject your model class. and pass your entity_id in $id



That's it! I hope it helps.




Update:



You can also get data by another field like below.



protected $customTablecollection;

public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelResourceModelMpsellermaplocatorcollection $mpSellerMapLocatorModel,
array $data = []
)
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;



And then you can use your variable directly in your code:



$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;





share|improve this answer

























  • can you get it by name ?

    – TN98
    Jun 7 at 4:40











  • Yes you can get it by name also but you have to use another methode.

    – Chirag Patel
    Jun 7 at 4:41











  • can you help me ? :(((

    – TN98
    Jun 7 at 4:42











  • Check my updated answer :)

    – Chirag Patel
    Jun 7 at 4:45











  • Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

    – TN98
    Jun 7 at 4:55
















2














Use load by Id to get data by id.



Try with below way.



Add below code in your block file.



<?php
namespace TestModuleBlock;

class TestBlock extends MagentoFrameworkViewElementTemplate


protected $customTable;


public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
NamespaceModuleNameModelcustomTableFactory $customTable

)


$this->customTable = $customTable;
parent::__construct($context);

public function getLoadProduct($id)

return $this->customTable->create()->load($id);





In the above code, I inject class NamespaceModuleNameModelcustomTableFactory in your case you have to inject your model class. and pass your entity_id in $id



That's it! I hope it helps.




Update:



You can also get data by another field like below.



protected $customTablecollection;

public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelResourceModelMpsellermaplocatorcollection $mpSellerMapLocatorModel,
array $data = []
)
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;



And then you can use your variable directly in your code:



$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;





share|improve this answer

























  • can you get it by name ?

    – TN98
    Jun 7 at 4:40











  • Yes you can get it by name also but you have to use another methode.

    – Chirag Patel
    Jun 7 at 4:41











  • can you help me ? :(((

    – TN98
    Jun 7 at 4:42











  • Check my updated answer :)

    – Chirag Patel
    Jun 7 at 4:45











  • Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

    – TN98
    Jun 7 at 4:55














2












2








2







Use load by Id to get data by id.



Try with below way.



Add below code in your block file.



<?php
namespace TestModuleBlock;

class TestBlock extends MagentoFrameworkViewElementTemplate


protected $customTable;


public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
NamespaceModuleNameModelcustomTableFactory $customTable

)


$this->customTable = $customTable;
parent::__construct($context);

public function getLoadProduct($id)

return $this->customTable->create()->load($id);





In the above code, I inject class NamespaceModuleNameModelcustomTableFactory in your case you have to inject your model class. and pass your entity_id in $id



That's it! I hope it helps.




Update:



You can also get data by another field like below.



protected $customTablecollection;

public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelResourceModelMpsellermaplocatorcollection $mpSellerMapLocatorModel,
array $data = []
)
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;



And then you can use your variable directly in your code:



$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;





share|improve this answer















Use load by Id to get data by id.



Try with below way.



Add below code in your block file.



<?php
namespace TestModuleBlock;

class TestBlock extends MagentoFrameworkViewElementTemplate


protected $customTable;


public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
NamespaceModuleNameModelcustomTableFactory $customTable

)


$this->customTable = $customTable;
parent::__construct($context);

public function getLoadProduct($id)

return $this->customTable->create()->load($id);





In the above code, I inject class NamespaceModuleNameModelcustomTableFactory in your case you have to inject your model class. and pass your entity_id in $id



That's it! I hope it helps.




Update:



You can also get data by another field like below.



protected $customTablecollection;

public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
WebkulMpSellerMapLocatorModelResourceModelMpsellermaplocatorcollection $mpSellerMapLocatorModel,
array $data = []
)
parent::__construct($context, $data);
$this->mpSellerMapLocatorModel = $mpSellerMapLocatorModel;



And then you can use your variable directly in your code:



$customId = 4;
$marketplaceMpsellermaplocator = $this->mpSellerMapLocatorModel->addFieldToFilter('custom_id', $customId);
echo "<pre>";var_dump($marketplaceMpsellermaplocator->getData());
exit;






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 7 at 5:08

























answered Jun 7 at 4:40









Chirag PatelChirag Patel

3,251627




3,251627












  • can you get it by name ?

    – TN98
    Jun 7 at 4:40











  • Yes you can get it by name also but you have to use another methode.

    – Chirag Patel
    Jun 7 at 4:41











  • can you help me ? :(((

    – TN98
    Jun 7 at 4:42











  • Check my updated answer :)

    – Chirag Patel
    Jun 7 at 4:45











  • Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

    – TN98
    Jun 7 at 4:55


















  • can you get it by name ?

    – TN98
    Jun 7 at 4:40











  • Yes you can get it by name also but you have to use another methode.

    – Chirag Patel
    Jun 7 at 4:41











  • can you help me ? :(((

    – TN98
    Jun 7 at 4:42











  • Check my updated answer :)

    – Chirag Patel
    Jun 7 at 4:45











  • Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

    – TN98
    Jun 7 at 4:55

















can you get it by name ?

– TN98
Jun 7 at 4:40





can you get it by name ?

– TN98
Jun 7 at 4:40













Yes you can get it by name also but you have to use another methode.

– Chirag Patel
Jun 7 at 4:41





Yes you can get it by name also but you have to use another methode.

– Chirag Patel
Jun 7 at 4:41













can you help me ? :(((

– TN98
Jun 7 at 4:42





can you help me ? :(((

– TN98
Jun 7 at 4:42













Check my updated answer :)

– Chirag Patel
Jun 7 at 4:45





Check my updated answer :)

– Chirag Patel
Jun 7 at 4:45













Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

– TN98
Jun 7 at 4:55






Hi Chirag Patel! You are right, thank you. can you check update question? i have a new issue, get data by custom_id

– TN98
Jun 7 at 4:55


















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277547%2fhow-to-get-data-from-custom-table-by-entity-id-for-custom-table-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form