symfony 数据库使用(二)
symfony可以根据数据用已经有表反向生成实体,以3.3.*为例:
php bin/console doctrine:mapping:import --force AppBundle xml
从现有数据库构建实体类的第一步是要求Doctrine内省数据库并生成相应的元数据文件。元数据文件描述要基于表字段生成的实体类。
生成元数据文件后,您可以通过执行以下命令让Doctrine构建相关的实体类。
php bin/console doctrine:mapping:convert annotation ./src 。若此命令没有响应可以尝试使用:php bin/console doctrine:mapping:import AppBundle annotation
新的实体类已生成如上图。
通过
php bin/console doctrine:generate:entities AppBundle 生成方法
实体已经生成了,那下面就是执行数据库操作的方法了,
需要了解数据库操作方法的可以访问:http://symfony.com/doc/3.3/doctrine.html
The first time when I saw her being meek that she might attain height.
The second time when I saw her limping before the crippled.
The third time when she was given to choose between the hard and the easy, and she chose the easy.
The fourth time when she committed a wrong, and comforted herself that others also commit wrong.
The fifth time when she forbore for weakness, and attributed her patience to strength.
The sixth time when she despised the ugliness of a face, and knew not that it was one of her own masks.
And the seventh time when she sang a song of praise, and deemed it a virtue.