Insert id into modal dialog's header

I have a CRUD inside a view and would like to add the $id of the current record to the modal dialog. The following does not work

 $crud->addModalAction(['', 'icon'=>'eye'], "PC detail view $id", function ($p, $id) {
   $p->add(new detail($id));
 });

Interestingly, $id works just fine for the callback but not for “PC detail view $id”. Where’s the catch?

Thanks.

I think the $id variable for the function is a different “scope” than what is being used for the addModalAction. Maybe from within the function itself you can set the title? What I usually do is call something like: return new \atk4\ui\jsModal(“PC detail view $id”…, or something similar from within the function itself, inside of an addAction call (instead of addModalAction).

This is because of the scope as gcooka mentioned. $id is available only in the callback.