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.
A property is like a combination of a variable and a method, and it has two methods: a get and a set method: The Name property is associated with the name field. It is a good practice to use the same name for both the property and the private field, but with an uppercase first letter.
A property is like a combination of a variable and a method, and it has two methods: a get and a set method: The Name property is associated with the name field. It is a good practice to use the same name for both the property and the private field, but with an uppercase first letter. The get method returns the value of the variable name.
@dave private properties can't be accessed outside of the class (as I'm sure you know). As such, there's not much use in having a get/set method for something you can access directly. public bool Monday { get; set; } // etc … (You don’t need your fields now, backing fields are generated by the compiler.)
Of course if you have a Persistent Object then the GET/SET methods are already generated for you. Actually in the 7.10 and higher code line (not be confused with 7.0 and its enhancement packages that run under the Business Suite), SAP has added GET/SET generation to the Refactoring capabilities within the class editor.
php app/console doctrine:generate:entities
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With