mootensai/yii2-seeder
Composer 安装命令:
composer require mootensai/yii2-seeder
包简介
A tool to quickly populate database with fake data
README 文档
README
--
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mootensai/yii2-seeder dev-master
or add
"mootensai/yii2-seeder": "dev-master"
to the require section of your composer.json file.
USAGE
console/config/main.php
'controllerMap' => [
'seeder' => [
'class' => 'mootensai\seeder\SeederController'
],
],
SEEDER COMMANDS
yii seeder Seed all tables in Database::run()
yii seeder [name] Seed a table
yii seeder [name]:[funtion_name] Seed a table and run a specific function from selected TableSeeder
namewithout TableSeeder (e.gyii seeder userforUserTableSeeder)
yii seeder/create model_name Create a TableSeeder in console\seeder\tables
For seeder, if the model is not at the root of the common/models, just add the folder where the model is located inside the common/models directory.
Example:
yii seeder/create entity/user
entity is the folder where User (model) is located inside the common/models directory.
To change the default path for models, just change the $modelNamespace variable in SeederController
Only Seeders within DatabaseSeeder::run() will be used in yii seeder command
SEEDER
EXAMPLE TEMPLATE
<?php namespace console\seeder\tables; use common\models\user\User; use console\seeder\DatabaseSeeder; use mootensai\seeder\TableSeeder; use Yii; class UserTableSeeder extends TableSeeder { function run() { loop(function ($i) { $this->insert(User::tableName(), [ 'email' => "user$i@gmail.com", 'name' => $this->faker->name, 'document' => $this->faker->numerify('##############'), 'street' => $this->faker->streetName, 'number' => $this->faker->numerify('###'), 'zip_code' => $this->faker->postcode, 'city' => $this->faker->city, 'status' => User::STATUS_USER_ACTIVE //created_at and updated_at are automatically added ]); }, DatabaseSeeder::USER_COUNT); } }
By default, all TableSeeder truncate the table before inserting new data, if you didn't want that to happen in a Seeder, just overwrite $skipTruncateTables:
public $skipTruncateTables = true;
default in TableSeeder:
public $skipTruncateTables = false; ... // truncate table $this->disableForeignKeyChecks(); $this->truncateTable(/* table names */); $this->enableForeignKeyChecks();
At the end of every Seeder, if any columns have been forgotten, a message with all the missing columns will appear
> #################### MISSING COLUMNS ################### > # TABLE: {{%user}} # > # name => varchar(255) # > # age => int(2) # > ########################################################
DatabaseSeeder
DatabaseSeeder will be created on first yii seeder/create model
Here you will put all TableSeeder in ::run()
to run, use yii seeder or yii seeder [name]
namewithout TableSeeder (e.gyii seeder userforUserTableSeeder)
DatabaseSeeder template:
DatabaseSeeder localization is console\seeder
class DatabaseSeeder extends TableSeeder { const MODEL_COUNT = 10; public function run() { ModelTableSeeder::create()->run(); } }
mootensai/yii2-seeder 适用场景与选型建议
mootensai/yii2-seeder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 412 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「widget」 「yii2」 「seeder」 「antonyz89」 「yii2-seeder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mootensai/yii2-seeder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mootensai/yii2-seeder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mootensai/yii2-seeder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
统计信息
- 总下载量: 412
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-05-03