5

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.

Borut Flis
  • 15,715
  • 30
  • 92
  • 119

2 Answers2

5
  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
DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • Does this effect all the models? What is the root of the symfony2 project. I am not sure about it because I didnt install doctrine in this project. I have a Symfony folder in libraries/Doctrine. – Borut Flis Feb 05 '13 at 08:54
  • Symfony2 project root is where you can find folder with these names: vendor,app,web. Yes, this will affect all. If you wanto to generate only fot a particulare bundle, you have to specify it after the command (on the same line) as a parameter. In case of Acme - DemoBundle, you'll write Acme/DemoBundle – DonCallisto Feb 05 '13 at 08:58
  • @BorutFlis: see my previous comment – DonCallisto Feb 05 '13 at 09:09
  • I cant find such a folder. – Borut Flis Feb 05 '13 at 09:10
  • @BorutFlis It isn't possibile: perharps a symfony2 app can't run if the app.php file isn't in it (and it is located into web folder at the root of the project) – DonCallisto Feb 05 '13 at 09:12
1

Since you are not mentioning Symfony, just run

vendor/bin/doctrine orm:generate:entities entities/

from the root directory of your project (replace entities/ with directory, where you stores your entity classes).

jkulak
  • 768
  • 1
  • 6
  • 18