Smo*_*otQ 24 doctrine annotations getter-setter symfony
我有以下ORM Symfony实体,只有属性:
<?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;
}
Run Code Online (Sandbox Code Playgroud)
我想自动生成setter和getter,所以我运行以下命令:
app/console doctrine:generate:entities Evr/HomeBundle/Entity/Article
Run Code Online (Sandbox Code Playgroud)
每次我这样做,它会显示以下错误消息:
[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
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不生成实体,实体/注释有什么问题?
ziz*_*jab 44
尝试:
app/console doctrine:generate:entities EvrHomeBundle:Article
Run Code Online (Sandbox Code Playgroud)
如果您使用的是symfony 3.0或更高版本,则使用bin替换app:
bin/console doctrine:generate:entities EvrHomeBundle:Article
Run Code Online (Sandbox Code Playgroud)
如果您使用的是symfony 4+,那么:
bin/console make:entity --regenerate
Run Code Online (Sandbox Code Playgroud)
Vic*_*sky 11
尝试删除此实体并使用下一个命令重新生成它们:
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"
Run Code Online (Sandbox Code Playgroud)
然后手动添加:
/**
*
* @ORM\ManyToOne(targetEntity="Subategory",inversedBy="articles")
* @ORM\JoinColumn(name="subcategory_id",referencedColumnName="id")
*/
private $subcategory;
Run Code Online (Sandbox Code Playgroud)
jco*_*der 10
php bin/console doctrine:generate:entities AppBundle
Run Code Online (Sandbox Code Playgroud)
这将自动生成所有必需的getter和setter到您的实体文件中.
如果您想具体了解表格,请使用以下内容:
php bin/console doctrine:generate:entities AppBundle:"TABLE_NAME"
Run Code Online (Sandbox Code Playgroud)
用您的表名替换"TABLE_NAME".
小智 5
映射导入(从数据库)
php bin/console doctrine:mapping:import 'AppBundle\Entity' yml --path=src/AppBundle/Resources/config/doctrine
Run Code Online (Sandbox Code Playgroud)
从映射生成实体,但没有 getter 和 setter
php bin/console doctrine:mapping:convert annotation ./src
Run Code Online (Sandbox Code Playgroud)
或者
通过 getter 和 setter 的映射生成实体
php bin/console doctrine:generate:entities AppBundle/Entity
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74736 次 |
| 最近记录: |