2

I am looking at the concept of the object manager, but I didn't get any proper explanation about that. I also have gone through the below link, but they are just explaining the usage, etc..

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/object-manager.html

But I want to know what is the object manager in magento2. Thanks in advance for your better support

1 Answer 1

6

The initializing of objects in Magento is done via what is called the object manager.

The object manager itself is an instance of the Magento\Framework\ObjectManager\ObjectManager class that implements the Magento\Framework\ObjectManagerInterface class. The ObjectManager class defines the following three methods:

  1. create($type, array $arguments = []): This creates a new object instance

  2. get($type): This retrieves a cached object instance

  3. configure(array $configuration): This configures the di instance

The object manager can instantiate a PHP class, which can be a model, helper, or block object. Unless the class that we are working with has already received an instance of the object manager, we can receive it by passing ObjectManagerInterface into the class constructor, as follows:

public function __construct(
    \Magento\Framework\ObjectManagerInterface $objectManager
)
{
    $this->_objectManager = $objectManager;
}

Get detailed information from https://www.vortexcommerce.com/magento-2-object-manager/

Hope it helps!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.