You know that in Symfony2 a new object can be defined as in the following example:
use Acme\StoreBundle\Entity\Product;
public function defaultController() {
$product = new Product();
$product->setName('Pippo');
$product->setPrice(19.99);
....
}
Suppose you know that the Product class has the following namespace: " AcmeHomeBundle: Product ". It would be nice to create a $ product object using a namespace (e.g. using EntityManager or something similar).
public function defaultController() {
$item = createObjectFromNamespace("AcmeHomeBundle:Product");
$item->setName('Pippo');
$item->setPrice(19.99);
....
}
Do you know if this is possible?
Suppose you have a string that provides an entity type
source
share