3

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?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Greast. I use now "getColumnNames" so I will recive all Names. Thank you. thats awesome :)
1

You can make use of ReflectionClass::getProperties() to loop through all properties.

http://php.net/manual/en/reflectionclass.getproperties.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.