Magento 2 , How to avaid load() in loop? The Next CEO of Stack OverflowIgnoring unused parameter with code snifferAvoiding save in a loop in mass actionHow to tackle with multiple time product load in magento?Controller not loading Grid container Error: Class 'Mage_Reviewmycompany_Helper_DataMagento 2 get Parameters in the URLMagento 2: Model edit form fields not loadingMass delete action in one step not in loop magento 2MEQP Gives a Warning : Data load getFirstItem() method detected in loopCreating new form in Magento 2 always getting errorDisable inline edit in ui listing

Term for the "extreme-extension" version of a straw man fallacy?

How to write papers efficiently when English isn't my first language?

Text adventure game code

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How do we know the LHC results are robust?

When Does an Atlas Uniquely Define a Manifold?

How to make a software documentation "officially" citable?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Why do remote companies require working in the US?

% symbol leads to superlong (forever?) compilations

Is it safe to use c_str() on a temporary string?

How did people program for Consoles with multiple CPUs?

Return the Closest Prime Number

Whats the best way to handle refactoring a big file?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

What happens if you roll doubles 3 times then land on "Go to jail?"

How can I open an app using Terminal?

Why is there a PLL in CPU?

Can a single photon have an energy density?

Should I tutor a student who I know has cheated on their homework?

Why does standard notation not preserve intervals (visually)

Visit to the USA with ESTA approved before trip to Iran



Magento 2 , How to avaid load() in loop?



The Next CEO of Stack OverflowIgnoring unused parameter with code snifferAvoiding save in a loop in mass actionHow to tackle with multiple time product load in magento?Controller not loading Grid container Error: Class 'Mage_Reviewmycompany_Helper_DataMagento 2 get Parameters in the URLMagento 2: Model edit form fields not loadingMass delete action in one step not in loop magento 2MEQP Gives a Warning : Data load getFirstItem() method detected in loopCreating new form in Magento 2 always getting errorDisable inline edit in ui listing










2















I have created the custom module with an inline edit in the grid, all working fine. once I have running phpsniffer with the EcgM2 standard, I get this warning:



Model LSD method load() detected in loop









share|improve this question
























  • refer this link github.com/magento/magento2/issues/10380

    – ABHISHEK TRIPATHI
    Feb 19 '18 at 13:13















2















I have created the custom module with an inline edit in the grid, all working fine. once I have running phpsniffer with the EcgM2 standard, I get this warning:



Model LSD method load() detected in loop









share|improve this question
























  • refer this link github.com/magento/magento2/issues/10380

    – ABHISHEK TRIPATHI
    Feb 19 '18 at 13:13













2












2








2


1






I have created the custom module with an inline edit in the grid, all working fine. once I have running phpsniffer with the EcgM2 standard, I get this warning:



Model LSD method load() detected in loop









share|improve this question
















I have created the custom module with an inline edit in the grid, all working fine. once I have running phpsniffer with the EcgM2 standard, I get this warning:



Model LSD method load() detected in loop






magento2 controllers optimization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 44 mins ago









Teja Bhagavan Kollepara

3,01241949




3,01241949










asked Feb 19 '18 at 13:10







user53836



















  • refer this link github.com/magento/magento2/issues/10380

    – ABHISHEK TRIPATHI
    Feb 19 '18 at 13:13

















  • refer this link github.com/magento/magento2/issues/10380

    – ABHISHEK TRIPATHI
    Feb 19 '18 at 13:13
















refer this link github.com/magento/magento2/issues/10380

– ABHISHEK TRIPATHI
Feb 19 '18 at 13:13





refer this link github.com/magento/magento2/issues/10380

– ABHISHEK TRIPATHI
Feb 19 '18 at 13:13










1 Answer
1






active

oldest

votes


















1














Use collection and filters to get list of models u need.



Sample below:



/** @var MagentoCatalogModelResourceModelProductCollectionFactory */
protected $collectionFactory;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory
)
$this->collectionFactory = $collectionFactory;


public function yourMethod()

// Use factory to create a new product collection
$productCollection = $this->collectionFactory->create();
/** Apply filters here */
$productCollection->addAttributeToSelect('*');
// Don't have to do this
// $productCollection->load();

foreach ($productCollection as $product)
echo 'Name = '.$product->getName().'<br>';







share|improve this answer

























  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rama Chandran M
    Oct 25 '18 at 10:56











  • @RamaChandranM its short, but still an answer ...

    – sv3n
    Oct 25 '18 at 11:07






  • 1





    @RamaChandranM I corrected my answer a little bit

    – Wojciech Ka
    Oct 25 '18 at 11:50






  • 1





    Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

    – Rama Chandran M
    Oct 25 '18 at 18:20











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%2f214086%2fmagento-2-how-to-avaid-load-in-loop%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









1














Use collection and filters to get list of models u need.



Sample below:



/** @var MagentoCatalogModelResourceModelProductCollectionFactory */
protected $collectionFactory;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory
)
$this->collectionFactory = $collectionFactory;


public function yourMethod()

// Use factory to create a new product collection
$productCollection = $this->collectionFactory->create();
/** Apply filters here */
$productCollection->addAttributeToSelect('*');
// Don't have to do this
// $productCollection->load();

foreach ($productCollection as $product)
echo 'Name = '.$product->getName().'<br>';







share|improve this answer

























  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rama Chandran M
    Oct 25 '18 at 10:56











  • @RamaChandranM its short, but still an answer ...

    – sv3n
    Oct 25 '18 at 11:07






  • 1





    @RamaChandranM I corrected my answer a little bit

    – Wojciech Ka
    Oct 25 '18 at 11:50






  • 1





    Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

    – Rama Chandran M
    Oct 25 '18 at 18:20















1














Use collection and filters to get list of models u need.



Sample below:



/** @var MagentoCatalogModelResourceModelProductCollectionFactory */
protected $collectionFactory;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory
)
$this->collectionFactory = $collectionFactory;


public function yourMethod()

// Use factory to create a new product collection
$productCollection = $this->collectionFactory->create();
/** Apply filters here */
$productCollection->addAttributeToSelect('*');
// Don't have to do this
// $productCollection->load();

foreach ($productCollection as $product)
echo 'Name = '.$product->getName().'<br>';







share|improve this answer

























  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rama Chandran M
    Oct 25 '18 at 10:56











  • @RamaChandranM its short, but still an answer ...

    – sv3n
    Oct 25 '18 at 11:07






  • 1





    @RamaChandranM I corrected my answer a little bit

    – Wojciech Ka
    Oct 25 '18 at 11:50






  • 1





    Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

    – Rama Chandran M
    Oct 25 '18 at 18:20













1












1








1







Use collection and filters to get list of models u need.



Sample below:



/** @var MagentoCatalogModelResourceModelProductCollectionFactory */
protected $collectionFactory;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory
)
$this->collectionFactory = $collectionFactory;


public function yourMethod()

// Use factory to create a new product collection
$productCollection = $this->collectionFactory->create();
/** Apply filters here */
$productCollection->addAttributeToSelect('*');
// Don't have to do this
// $productCollection->load();

foreach ($productCollection as $product)
echo 'Name = '.$product->getName().'<br>';







share|improve this answer















Use collection and filters to get list of models u need.



Sample below:



/** @var MagentoCatalogModelResourceModelProductCollectionFactory */
protected $collectionFactory;

public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $collectionFactory
)
$this->collectionFactory = $collectionFactory;


public function yourMethod()

// Use factory to create a new product collection
$productCollection = $this->collectionFactory->create();
/** Apply filters here */
$productCollection->addAttributeToSelect('*');
// Don't have to do this
// $productCollection->load();

foreach ($productCollection as $product)
echo 'Name = '.$product->getName().'<br>';








share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 25 '18 at 11:49

























answered Oct 25 '18 at 10:27









Wojciech KaWojciech Ka

14514




14514












  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rama Chandran M
    Oct 25 '18 at 10:56











  • @RamaChandranM its short, but still an answer ...

    – sv3n
    Oct 25 '18 at 11:07






  • 1





    @RamaChandranM I corrected my answer a little bit

    – Wojciech Ka
    Oct 25 '18 at 11:50






  • 1





    Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

    – Rama Chandran M
    Oct 25 '18 at 18:20

















  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

    – Rama Chandran M
    Oct 25 '18 at 10:56











  • @RamaChandranM its short, but still an answer ...

    – sv3n
    Oct 25 '18 at 11:07






  • 1





    @RamaChandranM I corrected my answer a little bit

    – Wojciech Ka
    Oct 25 '18 at 11:50






  • 1





    Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

    – Rama Chandran M
    Oct 25 '18 at 18:20
















This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

– Rama Chandran M
Oct 25 '18 at 10:56





This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review

– Rama Chandran M
Oct 25 '18 at 10:56













@RamaChandranM its short, but still an answer ...

– sv3n
Oct 25 '18 at 11:07





@RamaChandranM its short, but still an answer ...

– sv3n
Oct 25 '18 at 11:07




1




1





@RamaChandranM I corrected my answer a little bit

– Wojciech Ka
Oct 25 '18 at 11:50





@RamaChandranM I corrected my answer a little bit

– Wojciech Ka
Oct 25 '18 at 11:50




1




1





Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

– Rama Chandran M
Oct 25 '18 at 18:20





Thanks @sv3n, Thanks for updated ans Wqojciech. Some detail explain will help other.

– Rama Chandran M
Oct 25 '18 at 18:20

















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%2f214086%2fmagento-2-how-to-avaid-load-in-loop%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

Nidaros erkebispedøme

Birsay

Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?