The object manager
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:
create($type, array $arguments = [])
: This creates a new object instanceget($type)
: This retrieves a cached object instanceconfigure(array $configuration)
: This configures thedi
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; }
Usually, we don't have to take care of the constructor parameter...