I have to following entity :
/**
* ProductService
*
* @ORM\Table(name="sf_products_services")
* @ORM\Entity(repositoryClass="Evo\BackendBundle\Entity\ProductServiceRepository")
*/
class ProductService
{
[...]
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=150)
*/
protected $name;
[...]
How can I read the "length" value of the $name property ? I read I could use doctrine metadata, but I dont find anything about how to use it and how to read these data.
In accordion with the @wonde answer you can read the info you need thru the Doctrine metadata info as follow:
$doctrine = $this->getContainer()->get("doctrine");
$em = $doctrine->getManager();
$className = "Evo\BackendBundle\Entity\ProductService";
$metadata = $em->getClassMetadata($className);
$nameMetadata = $metadata->fieldMappings['name'];
echo $nameMetadata['type']; //print "string"
echo $nameMetadata['length']; // print "150"
Hope this help
getClassMetadata( mixed $className ) Returns the ORM metadata descriptor for a class
e.g
$metadata = $entityManager->getClassMetadata($className);
"The class name must be the fully-qualified class name without a leading backslash (as it is returned by get_class($obj)) or an aliased class name. Examples: MyProject\Domain\User sales:PriceRequest"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With