controllers/Controller.php
protected function importCSV($config, $fn = NULL)
    {
        $fileName = $config['fileName'];
        $file = fopen($fileName, "r");
        while (!feof($file)) {
            $record = fgetcsv($file, 0, $config['delimiter']);

            if (isset($record[0])) {

                //Parse attribute map
                $attributes = $this->parseAttributeMap($config['attributeMap'], $record);
                isset($fn) ? $fn($attributes, $config) : NULL;
                var_dump($attributes);
                $model = new $config['saveModel']();
                $model->setAttributes($attributes);
                $model->save();
            } else {
                break;
            }
        }
    }
protected function importCSV($config, $fn = NULL)
    {
        $fileName = $config['fileName'];
        $file = fopen($fileName, "r");
        while (!feof($file)) {
            $record = fgetcsv($file, 0, $config['delimiter']);

            if (isset($record[0])) {

                //Parse attribute map
                $attributes = $this->parseAttributeMap($config['attributeMap'], $record);
                isset($fn) ? $fn($attributes, $config) : NULL;
                var_dump($attributes);
                $model = new $config['saveModel']();
                $model->setAttributes($attributes);
                $model->save();
            } else {
                break;
            }
        }
    }
protected function importCSV ( $ config , $ fn = NULL ) { $ fileName = $ config [ 'fileName' ] ; $ file = fopen ( $ fileName , "r" ) ; while ( ! feof ( $ file ) ) { $ record = fgetcsv ( $ file , 0 , $ config [ 'delimiter' ] ) ; if ( isset ( $ record [ 0 ] ) ) { //Parse attribute map $ attributes = $ this -> parseAttributeMap ( $ config [ 'attributeMap' ] , $ record ) ; isset ( $ fn ) ? $ fn ( $ attributes , $ config ) : NULL ; var_dump ( $ attributes ) ; $ model = new $ config [ 'saveModel' ] ( ) ; $ model -> setAttributes ( $ attributes ) ; $ model -> save ( ) ; } else { break ; } } }
Import a CSV file

Imports a CSV table, in to a database provided an array of configuration options

- modelClassPath string

- columnMap array<int>=string Map of the columns

Protected as such methods can be overwritten and or extended

@param array<mixed> $config
Import a CSV file