相当于 Symfony 上的 Laravel 个播种机?

Equivalent of Laravel Seeders on Symfony?

我正在使用 Symfony 开发网站。我是这个框架的新手。在我使用 Laravel 5.0 之前,我需要一个包含行的数据库。

我在命令提示符下创建了我的数据库,但现在我找不到如何播种它。

Symfony 上有相当于 Laravel 播种机的东西吗?

没有。播种是 Laravel 添加的一项功能。您需要使用第三方包将 seeds/fixtures 加载到您的应用程序中:http://www.sitepoint.com/data-fixtures-symfony2/

试试这个包 https://packagist.org/packages/evotodi/seed-bundle。看来这就是你需要的。

他们的自述文件

Symfony/Doctrine Seed Bundle Used to load/unload seed data from the database. Example would be to load a table with a list of states and abbreviations, or populate the users table with initial admin user(s). Unlike the DoctrineFixturesBundle which is mainly for development this bundle is for seeding the database before the initial push to production.

这里的所有答案都有点过时了,这个问题是 google 上的第一个结果,所以对于未来的读者:

从 Symfony 3 开始,有一个 official bundle 用于这个目的

安装:composer require --dev doctrine/doctrine-fixtures-bundle

然后在src/DataFixtures和运行php bin/console doctrine:fixtures:load

中写下你的fixtures