getStateInfo
getStateInfo()
Get all the information about the state, inlcuding:
- The state as string
- All the state parameters
For example if you have an insert state then the state parameters are all the data for insert.
Example
The below example:
$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
if ($crud->getState() === 'EditForm') {
$stateInfo = $crud->getStateInfo();
$customerId = $stateInfo->primaryKeyValue;
// Mocking a minimal response of GroceryCRUD with an error message
// Custom error and json response with an error message is only available on Enterprise version
$output = (object)[
'isJSONResponse' => true,
'output' => json_encode(
(object)[
'message' =>
'You don\'t have permissions to edit the customer with ID: ' . $customerId,
'status' => 'failure'
]
)
];
} else {
$output = $crud->render();
}
Will have as an output the below result: