forked from pods-framework/pods
-
Notifications
You must be signed in to change notification settings - Fork 0
Import()
bonsak edited this page Nov 20, 2012
·
1 revision
Import data from an array or a CSV file.
public function import (
$import_data,
$numeric_mode = false,
$format = null
)
Parameter | Type | Details |
---|---|---|
$import_data | mixed | PHP associative array or CSV input |
$numeric_mode | bool | Use IDs instead of the name field when matching |
$format | string | Format of import data, options are php or csv |
(array) An array of the IDs for the items added
<?php
// Get the API
$api = pods_api( 'event' );
// Setup the data to import
$data = array(
0 => array(
'name' => 'My first event',
'start_date' => '2009-10-30 08:24:30',
'attendees' => array( 'Bill Gates', 'Steve Jobs', 'Mario Andretti' )
),
1 => array(
'name' => 'My second event',
'start_date' => '2012-12-25 06:45:00',
'attendees' => array( 'Al Gore', 'Bill Clinton' )
),
2 => array(
'name' => 'My third event',
'start_date' => '2010-01-20 11:59:99',
'attendees' => array( 'Rick Astley' )
)
);
// Run the import
$api->import( $data );
// Get CSV data
$data = file_get_contents( 'path/to/events.csv' );
// Run the import and set the format to CSV
$api->import( $data, false, 'csv' );
2.0+
import() is located in /pods/classes/PodsAPI.php