Вопрос

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.

Это было полезно?

Решение

  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

Другие советы

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top