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

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

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?