Download the PHP package diecoding/yii2-seeder without Composer
On this page you can find all versions of the php package diecoding/yii2-seeder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-seeder
Yii2 Seeder
Create fast-fill database with fake data or bulk data for Yii2.
Table of Contents
- Yii2 Seeder
- Table of Contents
- Instalation
- Dependencies
- Usage
- Config
- Basic Config
- Advanced Config
- Commands
- Example
- Seeder
Instalation
Package is available on Packagist, you can install it using Composer.
or add to the require section of your composer.json
file.
Dependencies
- PHP 7.4+
- yiisoft/yii2
- yiisoft/yii2-faker
Usage
Config
Add
controllerMap
to yourconfig
fileconsole/config/main.php
or in yii2-basicconfig/console.php
Basic Config
Advanced Config
Commands
yii seeder
Seed all tables in Seeder::run()
or this seed call $defaultSeederClass::run
yii seeder [name]
Seed a table
yii seeder [name]:[funtion_name]
Seed a table and run a specific function from selected TableSeeder
-
name
- full path / class name (e.g
yii seeder console\seeder\tables\UserTableSeeder
forUserTableSeeder
) - without TableSeeder (e.g
yii seeder user
forUserTableSeeder
) - with TableSeeder (e.g
yii seeder userTableSeeder
forUserTableSeeder
) - @see https://github.com/sugeng-sulistiyawan/yii2-seeder/blob/main/src/SeederController.php#L109 for more usage
- full path / class name (e.g
yii seeder/create [model_name]
Create a TableSeeder in console\seeder\tables\ModelNameTableSeeder
-
model_name
yii seeder/create model_name
yii seeder/create model-name
yii seeder/create full\path\Class
- @see https://www.yiiframework.com/doc/api/2.0/yii-helpers-inflector#camelize()-detail for handle
[model_name]
options
For seeder, if the model is not at the root of the
common/models
, just add the folder where the model is located inside thecommon/models
directory. You can configure with$modelNamespace
config in console\config.
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 Seeder::run()
will be used in yii seeder
command
Example
By default, all TableSeeder truncate the table before inserting new data, if you didn't want that to happen in a Seeder, just overwrite $truncateTable
:
default in TableSeeder:
By default, all TableSeeder faker locale/language get from Yii::$app->language
, if you want to use another locale just overwrite $locale
:
At the end of every Seeder, if any columns have been forgotten, a message with all the missing columns will appear
Seeder
Seeder
will be created on first yii seeder
if not exist
Here you will put all TableSeeder in ::run()
to run, use yii seeder
or yii seeder [name]
Seeder template:
Seeder
location in console\seeder
Read more docs: https://sugengsulistiyawan.my.id/docs/opensource/yii2/seeder/