Automatically creating installation methods for Doctrine

I use Doctrine. I need to make many models, and it would be nice if I didn't have to do everything manually,

I set the attributes as follows:

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

The get and set method is created from information that is fully included in the attribute declaration. So does anyone know of any tools that will generate get set methods, as shown below, from an 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; } 

I found this tool (Entity Generation) in the documentation of the doctrine, but it’s hard for me to understand what I should do.

+4
source share
2 answers
  • Go to the root of your symfony2 project
  • At a command prompt, type: php app/console doctrine:generate:entities
  • Enjoy auto generators and setters
+4
source

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 the directory in which the entity classes are stored).

+2
source

All Articles