Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Factory.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Catalog\Model;
11 
12 class Factory
13 {
19  protected $_objectManager;
20 
27  {
28  $this->_objectManager = $objectManager;
29  }
30 
39  public function create($className, array $data = [])
40  {
41  $model = $this->_objectManager->create($className, $data);
42 
43  if (!$model instanceof \Magento\Framework\Model\AbstractModel) {
44  throw new \Magento\Framework\Exception\LocalizedException(
45  __('%1 doesn\'t extends \Magento\Framework\Model\AbstractModel', $className)
46  );
47  }
48  return $model;
49  }
50 }
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
create($className, array $data=[])
Definition: Factory.php:39
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)
Definition: Factory.php:26
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31