Symfony3.4 数据库反向生成entity 已解决

9 篇文章 0 订阅

 映射数据库结构到文件(php\xml\yaml)

### 映射数据库结构到文件(php\xml\yaml)
[root@localhost ~]# cd /windows/www/symfony_test/
[root@localhost symfony_test]# php bin/console  doctrine:mapping:import --force AppBundle php
Importing mapping information from "default" entity manager
  > writing /windows/www/symfony_test/src/AppBundle/Resources/config/doctrine/Feedback.orm.php
  > writing /windows/www/symfony_test/src/AppBundle/Resources/config/doctrine/User.orm.php
  > writing /windows/www/symfony_test/src/AppBundle/Resources/config/doctrine/User.orm.php
 
 
 
### 生成entity
[root@localhost symfony_test]# php bin/console doctrine:mapping:convert annotation ./src
 
 Processing entity "AppBundle\Entity\Feedback"
 Processing entity "AppBundle\Entity\User"
 Processing entity "AppBundle\Entity\User"
 
 Exporting "annotation" mapping information to "/windows/www/symfony_test/src"
[root@localhost symfony_test]# 
[root@localhost symfony_test]# tree src/
src/
└── AppBundle
    ├── AppBundle.php
    ├── Controller
    │   ├── DefaultController.php
    │   └── UserController.php
    ├── Entity
    │   └── User.php
    ├── Repository
    │   ├── DemoRepository.php
    │   └── UserRepository.php
    ├── Resources
    │   └── config
    │       └── doctrine
    │           ├── User.orm.php
    └── Serverice
        └── UserService.php

 entity生成后,需要自己使用IDE工具生成getters和setters方法, 以及一些关联关系, 验证Assert提示信息
注意entity定义字段的格式,@var string|null必须要写,不然会找不到该字段

php bin/console doctrine:generate:entities AppBundle/Entity/Users

<?php
 
namespace AppBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
 
/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
 */
class User
{
    /**
     * @var string|null
     *
     * @ORM\Column(name="name", type="string", length=100, nullable=true)
     */
    private $name;
 
    /**
     * @var bool|null
     *
     * @ORM\Column(name="enabled", type="boolean", nullable=true, options={"default"="1"})
     */
    private $enabled = '1';
 
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;
}
php bin/console doctrine:mapping:import --force RelBundle annotation
 
生成get,set 自定义库
php bin/console doctrine:generate:entities RelBundle
php app/console doctrine:mapping:import "YourAppBundle" annotation --em=show --filter=DownloadRankingCoefficient
php app/console doctrine:generate:entities --no-backup YourAppBundle:DownloadRankingCoefficient

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PHP代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值