getState

string getState()

Simply get the state as a string. This is useful when you need to add a very specific implementation that it is outside of grocery CRUD Enterprise. A common usage to use the getState method is mainly if you need to have some permissions checks. Of course as this is something custom, you can specify the usage for getState for your own needs.

Below you can find the list of possible states for Grocery CRUD Enterprise edition that we have so far:

The most important states that are not so obvious to understand straight away are:

Example

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');

if ($crud->getState() === 'EditForm') {
    // 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' => 'It seems that you don\'t have access to edit this customer.',
                'status' => 'failure'
            ]
        )
    ];
} else {
    $output = $crud->render();
}

You can check the result of the above code below. Simply try to edit any customer. The above code is just an example, and we also agree that if this was a production code it would be a bad UX experience 😃