forked from pods-framework/pods
-
Notifications
You must be signed in to change notification settings - Fork 0
Save()
bonsak edited this page Nov 20, 2012
·
1 revision
Save an item by giving an array of field data or set a specific field to a specific value. Though this function has the capacity to add new items, best practice should direct you to use add() for that instead.
public function save (
$data = null,
$value = null,
$id = null
)
Parameter | Type | Details |
---|---|---|
$data | array | or string An associative array of field information or a field name |
$value | mixed | (optional) Value of the field, if $data is a field name |
$id | int | (optional) ID of the Pod item to update |
(int) The item ID
<?php
// Get the book item with an ID of 5
$pod = pods( 'book', 5 );
// Set the author (a user relationship field)
// to a user with an ID of 2
$pod->save( 'author', 2 );
// Set a group of fields to specific values
$data = array(
'name' => 'New book name',
'author' => 2,
'description' => 'Awesome book, read worthy!'
);
// Save the data as set above
$pod->save( $data );
// Let's save another book's data..
// Save the same data from above,
// but for the book with an ID of 4
$pod->save( $data, null, 4 );
Hooking into the Save / Delete process in the Pods API Contributed by owi See examples on how to use filters and actions to hook into the Save / Delete process in Pods API.
2.0+
save() is located in /pods/classes/Pods.php