{"id":16954070,"url":"https://github.com/le0m/yii2-import","last_synced_at":"2026-04-13T11:01:35.231Z","repository":{"id":57013142,"uuid":"132159664","full_name":"le0m/yii2-import","owner":"le0m","description":"Yii2 extension to import data from files.","archived":false,"fork":false,"pushed_at":"2018-05-04T15:50:28.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-01T22:16:59.328Z","etag":null,"topics":["csv-import","import","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/le0m.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-05-04T15:46:27.000Z","updated_at":"2022-07-25T14:29:02.000Z","dependencies_parsed_at":"2022-08-21T13:40:54.652Z","dependency_job_id":null,"html_url":"https://github.com/le0m/yii2-import","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/le0m/yii2-import","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0m%2Fyii2-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0m%2Fyii2-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0m%2Fyii2-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0m%2Fyii2-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/le0m","download_url":"https://codeload.github.com/le0m/yii2-import/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0m%2Fyii2-import/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31749763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["csv-import","import","yii2","yii2-extension"],"created_at":"2024-10-13T22:08:42.390Z","updated_at":"2026-04-13T11:01:35.209Z","avatar_url":"https://github.com/le0m.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yii2 Importer\n------------\n\nThis extension helps you import data from files like CSV or JSON into your application.\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\ncomposer require le0m/yii2-import\n```\n\nor add\n\n```\n\"le0m/yii2-import\": \"*\"\n```\n\nto the require section of your composer.json.\n\n\nUsage\n-----\n\nThis extension provide support to import data from files to data structures like array or ActiveRecord.\n\nFirst you must create an `Importer`, which needs a `reader` and an `importStrategy` to work, then you can import:\n\n```php\n$importer = new Importer([\n    // this can be an array of strings to use as column names for the imported data,\n    // `true` if the column names can be extracted from the file itself (the 'how' is specific to the implementation)\n    // or `false` to disable and not use column names (default).\n    'columnNames' =\u003e [...],\n    \n    // see below for how to setup this\n    'reader' =\u003e [\n        'class' =\u003e '\\common\\components\\importer\\CsvReader',\n    ],\n    \n    // see below for how to setup this\n    'importStrategy' =\u003e [\n        'class' =\u003e '\\common\\components\\importer\\ARImportStrategy',\n    ]\n]);\n\n// get the imported data\n$data = $importer-\u003eimport();\n```\n\nThe importer will read the file using the chosen `reader` implementation, passing each element to the chosen `importStrategy` implementation. The returning value is an array of imported data.\n\nIf the `importStrategy` return `false` on a single element, the `Importer` will ignore it.\n\nBy default this extension provides two reader (CSV and JSON) and two import strategy (to array and to ActiveRecord) implementations to choose from, but you can add your own by implementing the appropriate interface.\n\n\n**Import a CSV file**\n\nThe `CsvReader` accepts the following properties:\n\n```php\n'reader' =\u003e [\n    'class' =\u003e '\\common\\components\\importer\\CsvReader',\n    \n    // limit the max length of a single line to read from file\n    // 0 means no limit\n    'lineLength' =\u003e 0,\n    \n    // character used to separate values on a single line\n    'valueDelimiter' =\u003e \",\",\n    \n    // character used to enclose values\n    'valueEnclosure' =\u003e '\"',\n    \n    // character used as escape in the values\n    'escapeCharacter' =\u003e \"\\\\\",\n]\n```\n\n\n**Import a JSON**\n\nThe `JsonImporter` has no particular properties:\n\n```php\n'reader' =\u003e [\n    'class' =\u003e '\\common\\components\\importer\\JsonReader',\n]\n```\n\n\n**Import to ActiveRecord**\n\nThe `ARImportStrategy` accepts the following properties:\n\n```php\n'importStrategy' =\u003e [\n    'class' =\u003e '\\common\\components\\importer\\ARImportStrategy',\n    \n    // name of the ActiveRecord class to use for the import\n    'className' =\u003e '...',\n    \n    // if you need custom code to handle loading data read from the file to the AR\n    // (ex. column names from the file are different than property names from the AR\n    // this function will be called for each element in the original file,\n    // return false to not import the current element ([[Importer]] ignores false elements)\n    'loadProperties' =\u003e function ($model, $data) { ... },\n    \n    // whether to automatically save the AR at the end of the import\n    // AR with validation errors are returned anyway\n    'saveRecord' =\u003e true,\n]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0m%2Fyii2-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fle0m%2Fyii2-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0m%2Fyii2-import/lists"}