Skip to content
bonsak edited this page Nov 20, 2012 · 1 revision

import()

Import data from an array or a CSV file.

public function import ( 
	$import_data, 
	$numeric_mode = false, 
	$format = null 
)

Parameters

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

Returns

(array) An array of the IDs for the items added

Example

<?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' );

Available Since Version

2.0+

Source File

import() is located in /pods/classes/PodsAPI.php

See Also