Using object manager in PHTML files directly good practice or not, if not then why ?
Example:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create(‘Magento\Catalog\Model\Product’)->load($id);
Using object manager in PHTML files directly good practice or not, if not then why ?
Example:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create(‘Magento\Catalog\Model\Product’)->load($id);
Everybody says that it is, but I think it is generally not an issue.
There is a small issue that the such code is longer, so for a long-term project I recomment to refactor it.
Also, your code has a much bigger issue than Object Manager: you loads a product from the database directly.
It is very bad: it hurts the Magento’s performance.
Learn about object repositories.