在 Symfony/Doctrine ORM 中生成实体 Getter 和 Setter [英] Generating Entity Getters and Setters in Symfony / Doctrine ORM
本文介绍了在 Symfony/Doctrine ORM 中生成实体 Getter 和 Setter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下只有属性的 ORM Symfony 实体:
I have the following ORM Symfony entity with only properties :
<?php
namespace Evr\HomeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="ev_article")
* @ORM\Entity
*/
class Article
{
/**
*
* @ORM\Column(name="article_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @ORM\ManyToOne(targetEntity="Subategory",inversedBy="articles")
* @ORM\JoinColumn(name="subcategory_id",referencedColumnName="id")
*/
private $subcategory;
/**
*
* @ORM\Column(type="string",length=512)
*/
private $title;
/**
*
* @ORM\Column(type="text")
*/
private $content;
/**
*
* @ORM\Column(type="text")
*/
private $exclusive_content;
/**
*
* @ORM\Column(type="date")
*/
private $creation_date;
/**
*
* @ORM\Column(type="integer")
*/
private $views;
/**
*
* @ORM\Column(type="integer")
*/
private $votes;
}
我想自动生成 setter 和 getter,所以我运行以下命令:
I want to generate setters and getters automatically, so I run the following command :
app/console doctrine:generate:entities Evr/HomeBundle/Entity/Article
每次我这样做时,它都会显示以下错误消息:
And everytime I do this, it displays the following error message :
[Doctrine\ORM\Mapping\MappingException]
Class "Evr\HomeBundle\Entity\Article" is not a valid entity or mapped super
class.
doctrine:generate:entities [--path="..."] [--no-backup] name
我不知道为什么它不生成实体,实体/注释有问题吗?
I don't know why it doesn't generate entities, is something wrong in the entity/annotations?
推荐答案
尝试删除此实体并使用下一个命令重新生成它们:
Try to delete this entity and regenerate them with next command:
php app/console doctrine:generate:entity --entity="EvrHomeBundle:Article" --fields="name:string(255) content:text exclusive_content:text creation_date:date views:integer votes:integer"
然后手动添加:
/**
*
* @ORM\ManyToOne(targetEntity="Subategory",inversedBy="articles")
* @ORM\JoinColumn(name="subcategory_id",referencedColumnName="id")
*/
private $subcategory;
这篇关于在 Symfony/Doctrine ORM 中生成实体 Getter 和 Setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文