{"id":19571744,"url":"https://github.com/loadsys/cakephp-basic-seed","last_synced_at":"2026-03-06T13:04:12.489Z","repository":{"id":18216944,"uuid":"21354489","full_name":"loadsys/CakePHP-Basic-Seed","owner":"loadsys","description":"Provides a simple mechanism for seeding data into an application's database.","archived":false,"fork":false,"pushed_at":"2018-06-19T19:32:18.000Z","size":34,"stargazers_count":4,"open_issues_count":4,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-21T08:46:28.955Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loadsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-30T14:42:49.000Z","updated_at":"2019-03-25T20:03:21.000Z","dependencies_parsed_at":"2022-09-14T13:53:04.284Z","dependency_job_id":null,"html_url":"https://github.com/loadsys/CakePHP-Basic-Seed","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Basic-Seed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Basic-Seed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Basic-Seed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Basic-Seed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadsys","download_url":"https://codeload.github.com/loadsys/CakePHP-Basic-Seed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251085145,"owners_count":21533821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T06:19:54.833Z","updated_at":"2026-03-06T13:04:12.428Z","avatar_url":"https://github.com/loadsys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CakePHP-Basic-Seed\n\n[![Latest Version](https://img.shields.io/github/release/loadsys/CakePHP-Basic-Seed.svg?style=flat-square)](https://github.com/loadsys/CakePHP-Basic-Seed/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/cakephp-basic-seed.svg?style=flat-square)](https://packagist.org/packages/loadsys/cakephp-basic-seed)\n\nProvides a simple mechanism for seeding data into your CakePHP application's database.\n\n## Requirements\n\n* PHP 5.6+\n* CakePHP 3.0+\n\n:warning: Check the [cake-2.x branch](https://github.com/loadsys/CakePHP-Basic-Seed/tree/cake-2.x) for the CakePHP v2.x compatible version. The `1.x.x` semver series maintains compatibility with CakePHP 2, while `~2` tracks CakePHP 3.\n\n\n## Installation\n\n### Composer\n\n````bash\n$ composer require loadsys/cakephp-basic-seed:~2.0\n````\n\n## Usage\n\n* Add this plugin to your application by adding this line to your `bootstrap.php`:\n\n````php\nPlugin::load('BasicSeed', ['bootstrap' =\u003e false, 'routes' =\u003e false]);\n````\n\nThis is a command line plugin. To use it:\n\n````bash\nbin/cake BasicSeed.basic_seed\n# Runs the `config/seed.php` seed file.\n\n# or\nbin/cake BasicSeed.basic_seed --dev\n# Runs `config/seed_dev.php` seed file.\n````\n\nYou can also specify `--file` and it will use the file specified (inside of `config/`)\n\n````bash\nbin/cake BasicSeed.basic_seed --file seed_staging.php\n# Will use the file located at `config/seed_staging.php`.\n# This option always overrides --dev.\n````\n\n\nTo create a `seed.php` file, run the `init` command:\n\n````bash\nbin/cake BasicSeed.basic_seed init\n````\n\nTo create a `seed_dev.php` file:\n\n````bash\nbin/cake BasicSeed.basic_seed init --dev\n````\n\nTo create a custom seed file, you can use the `--file` parameter.\n\n````bash\nbin/cake BasicSeed.basic_seed init --file seed_staging.php\n````\n\n## Writing a Seed\n\nThe plugin provides a number of helper methods to help get data into your application more efficiently. The most notable of these is `$this-\u003eimportTables($data)`. This method takes an array structure and iterates over it, converting the array data into Entities and saving them into each named table. The generate structure of the array is as follows:\n\n```php\n\u003c?php\n/**\n * Example BasicSeed plugin data seed file.\n *\n * Typically in `config/seed.php` or `config/seed_dev.php`.\n */\n\nnamespace App\\Config\\BasicSeed;\n\n// Write your data import statements here.\n\n$data = [\n\t/**\n\t * Each key in the top-level of the array must be the proper name of a\n\t * Table into which the contained records will be imported.\n\t */\n\t'TableName' =\u003e [\n\n\t\t/**\n\t\t * When _truncate is enabled, ALL existing records will be removed\n\t\t * from the table before loading!\n\t\t */\n\t\t//'_truncate' =\u003e true,\n\n\t\t/**\n\t\t * The _entityOptions array is passed to Table::newEntity() and\n\t\t * Table::patchEntity(). It can be used to disable validation.\n\t\t *\n\t\t * Also be aware that the Shell sets\n\t\t * `['accessibleFields' =\u003e ['*' =\u003e true]]` by default in order to\n\t\t * more easily \"prime\" new Entities with all of the values\n\t\t * specified in $data, including fixed primary keys. This bypasses\n\t\t * your normal Entity `::$_accessible` settings, so it's good to\n\t\t * be aware of this if you're using a seed to \"refresh\" existing\n\t\t * data.\n\t\t */\n\t\t//'_entityOptions' =\u003e [\n\t\t//\t'validate' =\u003e false,\n\t\t//],\n\n\t\t/**\n\t\t * The _saveOptions array is passed to Table::save(). It can be\n\t\t * used to disable rules checking.\n\t\t */\n\t\t//'_saveOptions' =\u003e [\n\t\t//\t'checkRules' =\u003e false,\n\t\t//],\n\n\t\t/**\n\t\t * You can provide default values that will be merged into each\n\t\t * record before the Entity is created. Can be used to reduce\n\t\t * unnecessary repetition in imported records.\n\t\t */\n\t\t'_defaults' =\u003e [\n\t\t    'is_active' =\u003e true,\n\t\t],\n\n\t\t/**\n\t\t * Everything else is counted as a separate record to import.\n\t\t * Remember that combined with [_defaults], you only need to specify\n\t\t * the **unique** fields for each record.\n\t\t */\n\t\t[\n\t\t\t/**\n\t\t \t * Existing DB records will be matched and updated using the\n\t\t \t * primary key, if provided. Otherwise, the Shell will simply\n\t\t \t * attempt to insert every record, so be mindful of fields\n\t\t \t * that require uniqueness.\n\t\t \t */\n\t\t \t'id' =\u003e 1,\n\t\t\t'name' =\u003e 'record 1',\n\t\t],\n\t],\n];\n\n/**\n * Perform the data import using the array structure above.\n */\n$this-\u003eimportTables($data);\n\n/**\n * If you want to import another seed file in addition to this one (say\n * for example that in development, you want all of your seed_dev data,\n * **plus** all of your seed data from production), you can call the\n * import yourself directly:\n */\n$this-\u003ehr();\n$this-\u003eout('\u003cinfo\u003eLoading production data in addition to dev data...\u003c/info\u003e');\n$this-\u003eincludeFile($this-\u003eabsolutePath('seed.php'));\n\n\n```\n\nRemember that the seed file is just an extension of the BasicSeedShell and that seeds do not _have_ to conform to the above structure. You have access to anything you could normally do from inside a Shell, so for example, this is also a valid seed file:\n\n```php\n\u003c?php\n/**\n * Another example BasicSeed plugin data seed file.\n */\n\nnamespace App\\Config\\BasicSeed;\n\n$Posts = $this-\u003eloadModel('Posts');\n$posts = [\n\t['id' =\u003e 1, 'title' =\u003e 'Foo', 'body' =\u003e 'Lorem ipsum.'],\n\t['id' =\u003e 2, 'title' =\u003e 'Bar', 'body' =\u003e 'The meaning of life is 42.'],\n];\n\nforeach ($posts as $p) {\n\t$entity = $Posts-\u003enewEntity($p); // Careful, validation is still on!\n\tif($Posts-\u003esave($entity)) {\n\t\t$this-\u003eout(\"Saved {$entity-\u003eid}\");\n\t} else {\n\t\t$this-\u003ewarning(\"Save failed where title = {$entity-\u003etitle}\");\n\t}\n}\n\n```\n\n...although it's worth point out that `::importTables()` performs a more robust version of this exact process for you, including dumping validation errors when they are encountered.\n\n\n## Contributing\n\n### Reporting Issues\n\nPlease use [GitHub Isuses](https://github.com/loadsys/CakePHP-Basic-Seed/issues) for listing any known defects or issues.\n\n### Development\n\nWhen developing this plugin, please fork and issue a PR for any new development.\n\n\n## License ##\n\n[MIT](https://github.com/loadsys/CakePHP-Basic-Seed/blob/master/LICENSE.md)\n\n\n## Copyright ##\n\n[Loadsys Web Strategies](http://www.loadsys.com) 2015\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Fcakephp-basic-seed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadsys%2Fcakephp-basic-seed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Fcakephp-basic-seed/lists"}