callbackReadField(string $fieldName, callable $callback)

Create a custom field with a callback for read/view form. As parameters we are getting two parameters:

  1. The value of the field from the database for that row
  2. The primary key value of the row in case you need to use it for an extra manual query

For example:

$crud->callbackReadField('contact_telephone_number', function ($fieldValue, $primaryKeyValue) {
    return '+30 ' . $fieldValue;

Have in mind that from PHP 5.4 and later there is an extra functionality with keywork use, so that means that you can pass any extra parameters at the callback from outside the callback if you wish it. For example:

$username = 'john';
$crud->callbackReadField('contact_telephone_number', function ($fieldValue, $primaryKeyValue) use ($username) {
     // You have access now at the extra custom variable $username
    return '+30 ' . $fieldValue . ' for: ' . $username;

Notice: Grocery CRUD Enterprise is all about security so we are obliged to inform you that the callbackReadField is using the: dangerouslySetInnerHTML function of reactJS. As you can understand from the name, this may be very dangerous if it is not used properly. We are suggesting to use it mainly in admin environments and make sure that you are always filtering your data at the callback. This was the only way that we could enable the functionality of callbackReadField and you have to be aware of this warning before using it.