Auto generate get set methods for Doctrine

Borut Flis picture Borut Flis · Feb 5, 2013 · Viewed 8.1k times · Source

I am using Doctrine I have to make a lot of models, and it would be nice if I wouldnt have to do everything manually.

I set and attribute like this:

/**
     * @var string $name
     *
     * @Column(name="Name", type="string", length=100, nullable=false)
     */
    private $name;

The get & set method are made from information, which is entirely included in the attribute declaration. So does anyone know any tools that would generate the get set methods like below from the attribute declaration.

 /**
     * Set name
     *
     * @param string $name
     * @return User
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

In the doctrine documentation I found this tool(Entity Generation), but I have trouble understanding what I should do.

Answer

DonCallisto picture DonCallisto · Feb 5, 2013
  1. Navigate to the root of your symfony2 project
  2. Type into your command-line shell: php app/console doctrine:generate:entities
  3. Enjoy your auto-generated getters and setters