Get all the information about the state, inlcuding:

  1. The state as string
  2. All the state parameters

For example if you have an insert state then the state parameters are all the data for insert.


The below example:

$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(
                '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: