Symfony gets values ββfrom Entity
Is it possible to read all available values ββfrom an object?
eg.
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, I will get the name Value, for example: Id, UserID, Sport?
+3
source to share
2 answers
You can read the information you need through the Doctrine metadata information like this:
$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 information on API DOC
Hope for this help
+4
source to share