Symfony getData() return null value

843 views Asked by At

I am new in Symfony, i had existing Document as User.php, Here is my old file.

use FOS\UserBundle\Model\User as BaseUser;

class User extends BaseUser
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $name;

    /**
     * @MongoDB\Field(type="string")
     */
    protected $email;

    public function getId()
    {
        return $this->id;
    }

    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    public function getName()
    {
       return $this->name;
    }

}

Then i need to add new filed email, then i changed User.php, here is updated file.

use FOS\UserBundle\Model\User as BaseUser;

    class User extends BaseUser
    {
        /**
         * @MongoDB\Id(strategy="auto")
         */
        protected $id;

        /**
         * @MongoDB\Field(type="string")
         */
        protected $name;

        /**
         * @MongoDB\Field(type="string")
        */
       protected $email;

        public function getId()
        {
            return $this->id;
        }

        public function setName($name)
        {
            $this->name = $name;

            return $this;
        }

        public function getName()
        {
           return $this->name;
        }

        public function setEmail($email)
        {
            $this->email = $email;

            return $this;
        }

        public function getEmail()
        {
           return $this->email;
        }

    }

Then i tried to get value of email its show null, I cheeked my database and there is value is exist in email field. Here is my code.

$user = $this->dm()->getRepository('UserBundle:User')->find($id);
var_dump($user->getEmail());

i also removed all cache using following commands.

php app/console doctrine:cache:clear-metadata 
php app/console doctrine:cache:clear-query  
php app/console doctrine:cache:clear-result 

also remove cache using rm -rf var/cache but its still give null value. whats wrong with me? can you help me?

1

There are 1 answers

2
megadruck On

Email is already defined in Baseuser. Maybe you have To add parent::getEmail() or remove the getter totally