Export & Import
Move data in and out — CSV, Excel, JSON, XML. You can reshape rows on the way out, and validate or transform rows on the way in. Each recipe says exactly where the code goes.
Events these pages fire
| Event | Where | Use for |
|---|---|---|
| Before Export | Table → Page Events (PHP) | Choose/limit the rows, add columns, mask sensitive fields. |
| After Export | Table → Page Events (PHP) | Log the export, notify someone. |
| Before Import | Table → Page Events (PHP) | Validate + transform each incoming row; skip bad ones. |
| After Import | Table → Page Events (PHP) | Summarise, recalculate, or notify after the load. |
| Custom WHERE | Table → SQL Modifiers | Export respects the same row filter as the List page. |
Export recipes
1 · Add a computed column to the export
WhereEvents → orders → Page Events → Before ExportPHP
foreach ($data as &$row) {
$row['margin'] = (float) $row['price'] - (float) $row['cost'];
}
unset($row);
2 · Mask a sensitive field in exports
WhereEvents → customers → Page Events → Before ExportPHP
foreach ($data as &$row) {
if (!empty($row['email'])) $row['email'] = preg_replace('/(?<=.).(?=.*@)/', '*', $row['email']);
}
unset($row);
3 · Only export the current user's rows
WhereEvents → orders → SQL Modifiers → Custom WHEREPHP
if (!\PpPhp\Core\Auth\Permissions::isAdmin()) {
return 'created_by = ' . (int) (\PpPhp\Core\Security::CurrentUserData()['id'] ?? 0);
}
return '';
4 · Log every export
WhereEvents → orders → Page Events → After ExportPHP
dbExecute('INSERT INTO export_log (table_name, rows, "by", at) VALUES (?,?,?,?)',
['orders', count($data), \PpPhp\Core\Security::CurrentUsername(), now()]);
Import recipes
5 · Validate & clean each incoming row
WhereEvents → customers → Page Events → Before ImportPHP
// $data is one incoming row (by reference). Return false to skip it.
$data['email'] = strtolower(trim($data['email'] ?? ''));
if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
return false; // skip rows without a valid email
}
$data['imported_at'] = now();
6 · Look up a foreign key from a name during import
WhereEvents → orders → Page Events → Before ImportPHP
// the CSV has a customer NAME; store the id
$id = dbValue('SELECT id FROM customers WHERE name = ?', [$data['customer_name'] ?? '']);
if (!$id) return false; // unknown customer → skip
$data['customer_id'] = (int) $id;
unset($data['customer_name']);
7 · Recalculate totals after a bulk import
WhereEvents → orders → Page Events → After ImportPHP
dbExecute('UPDATE orders o SET total = (SELECT COALESCE(SUM(qty*price),0) FROM order_items WHERE order_id = o.id)');
Import events run on trusted, author-written code and every value is bound as a parameter
in your DB calls — never glue an imported value into SQL. See Database Helpers.