setMasterDetail
setMasterDetail(string $apiUrl)
Example
Customers CRUD:
$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->setMasterDetail("https://full/url/path/to/orders.php");
$crud->setRead();
$crud->setClone();
$output = $crud->render();
Orders CRUD:
$crud->setTable('orders');
$crud->setSubject('Order', 'Orders');
$crud->unsetTools();
$crud->unsetSearchColumns(['orderNumber', 'orderDate', 'requiredDate', 'shippedDate', 'status', 'comments', 'customerNumber']);
$crud->fieldType('customerNumber', 'hidden');
if (!empty($_POST['master_id'])) {
if (is_numeric($_POST['master_id'])) {
$crud->where(['customerNumber' => $_POST['master_id']]);
} else {
throw new InvalidArgumentException("Invalid argument for the field 'master_id'");
}
}
$crud->callbackBeforeInsert(function ($stateParameters) {
if (!empty($_POST['master_id'])) {
if (is_numeric($_POST['master_id'])) {
$stateParameters->data['customerNumber'] = $_POST['master_id'];
} else {
throw new InvalidArgumentException("Invalid argument for the field 'master_id'");
}
}
return $stateParameters;
});
$output = $crud->render();