class CsvImport

Class CsvImport Import Helper to use CSV files for model generation. The helper loops through all rows, generates a new model and passed the columns as property. Use the provided set_before_model_save() and set_after_model_save() to add custom code to be executed during the creation, e.g. if you need to call a custom model function or you need to convert data prior saving.

Example: $seed_instance = $XF->im->get_instance('my_groups'); $seed = new CsvImport($seed_instance, 'group'); $seed->set_source(dirname(FILE).'/data/group.csv'); $seed->import();

Methods

__construct(Core $seed_instance, string $model_name)

CsvImport constructor.

import(string $delimiter = ';')

Runs the import process and generates the models

set_after_model_save($callback)

Executed for each generated model AFTER saving it

set_before_model_save($callback)

Executed for each generated model BEFORE saving it

set_source(string $csv_file)

Sets the CSV File which should be loaded

Details

at line 66
__construct(Core $seed_instance, string $model_name)

CsvImport constructor.

Parameters

Core $seed_instance

XELOS Instance Object

string $model_name

Name of Model which should be generated

at line 103
import(string $delimiter = ';')

Runs the import process and generates the models

Parameters

string $delimiter

Exceptions

Exception

at line 92
set_after_model_save($callback)

Executed for each generated model AFTER saving it

Parameters

$callback

at line 84
set_before_model_save($callback)

Executed for each generated model BEFORE saving it

Parameters

$callback

at line 76
set_source(string $csv_file)

Sets the CSV File which should be loaded

Parameters

string $csv_file

Path to CSV File