映射数据库结构到文件(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