From this website:
Manually Load Object Manager
You should avoid calling the object manager directly as this is not the proper way, but if you have to you use:
$om = \Magento\Framework\App\ObjectManager::getInstance(); /* use object manager to get a class for example the attribute repository */ $attr = $om->get('\Magento\Eav\Api\AttributeRepositoryInterface'); /* use returned class attribute repository to get the attribute id of the name for products */ $productNameAttributeId = $attr->get('catalog_product', 'name')->getId();
It states:
this is not proper way, but if you have to you use
How can I do this the proper way?
ObjectManager
directly, as M2 doesn't expand on that: mwop.net/blog/2016-04-26-on-locators.html