Reputation: 1054
Is there a possibility to read all available Values from an entity?
E.G.
class Properties
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="UserID", type="string", length=255)
*/
private $userID;
/**
* @var string
*
* @ORM\Column(name="Sport", type="string", length=1)
*/
private $sport;
.
.
.
So that I will get the name of the Value like: Id, UserID, Sport?
Upvotes: 3
Views: 5394
Reputation: 3085
You can make use of ReflectionClass::getProperties()
to loop through all properties.
http://php.net/manual/en/reflectionclass.getproperties.php
Upvotes: 1
Reputation: 39470
You can read the info you need thru the Doctrine metadata info as follow:
$doctrine = $this->getContainer()->get("doctrine");
$em = $doctrine->getManager();
$className = "Acme\DemoBundle\Entity\Properties";
$metadata = $em->getClassMetadata($className);
$nameMetadata = $metadata->fieldMappings['sport'];
echo $nameMetadata['type']; //print "string"
echo $nameMetadata['length']; // print "1"
// OR query for all fields
// Returns an array with all the identifier column names.
$metadata->getIdentifierColumnNames();
More info on the API DOC
Hope this help
Upvotes: 4