简体   繁体   English

教义会创造二传手和吸气剂?

[英]Doctrine create setters and getters?

OK, I am missing something here ... I want to start using Doctrine 2. Now I created an entity class "recepie" with annotations: 好的,我这里缺少什么……我想开始使用Doctrine2。现在,我创建了带有注释的实体类“ recepie”:

/**
* @Entity
*/

class recepie 
{

  /**
  * @Id @Column(type="integer")
  * @GeneratedValue
  */
  private $id;

  /** @Column(length=500) */
  private $titleDE;

  /** @Column(length=4000) */
  private $descDE;

  /** @Column(length=4000) */
  private $instructDE;

  /** @Column(type="date") */
  private $postedAt;

  /** @Column(type="integer") */
  private $skill;

  /** @Column(type="integer") */
  private $prepTime;

  /** @Column(type="smallint") */
  private $personNum;

  /** @Column(type="boolean") */
  private $isPublic;


}

Now I try to auto generate setters and getters using: 现在,我尝试使用以下方法自动生成setter和getter:

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

Now this creates a new file called "recipie.php~", probably not to overwrite the existing recipie.php file that contains the initial entity. 现在,这将创建一个名为“ recipie.php〜”的新文件,可能不会覆盖包含初始实体的现有recipie.php文件。

What is the idea here ? 这是什么主意? Am I supposed to open that file and copy/paste the getters and setters into my initial entity class ? 我是否应该打开该文件并将获取器和设置器复制/粘贴到我的初始实体类中? What am I missing ? 我想念什么?

Your idea is on the right track, but not quite right. 您的想法是正确的,但不是很正确。 Actually generate-entities does modify your existing entity file, and those files with ~ appended to their names are just backup files that generate-entities creates beforehand. 实际上, generate-entities 确实会修改您现有的实体文件,并且那些在文件名后加上~文件只是那些generate-entities事先创建的备份文件。

The accessor methods should be created in the original file. 访问器方法应在原始文件中创建。 If everything looks okay, you can delete the backup file. 如果一切正常,则可以删除备份文件。 You shouldn't have to copy and paste anything from it. 您不必复制并粘贴任何内容。 If you want to run generate-entities without creating those files, you can use the --no-backup option. 如果要运行generate-entities而不创建这些文件,则可以使用--no-backup选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM