Php 使用变量到DataTables服务器端列值格式化程序

Php 使用变量到DataTables服务器端列值格式化程序,php,datatables,server-side,Php,Datatables,Server Side,我想通过服务器端格式化程序在数据表的每个单元格上传递PHP函数,但PHP函数是动态的。下面是示例代码: $func_apply = $_GET['function_name']; // trim | strip_tags | md5 | ucwords $columns[] = array( 'db' => $field, 'dt' => '3', 'formatter' => function( $d, $row ) {

我想通过服务器端格式化程序在数据表的每个单元格上传递PHP函数,但PHP函数是动态的。下面是示例代码:

$func_apply = $_GET['function_name']; // trim | strip_tags | md5 | ucwords

$columns[] = array(
'db'        => $field,
'dt'        => '3',
'formatter' => function( $d, $row ) {
                return $func_apply($d);
            }
);
但这样我得到了PHP错误未定义变量:$func_apply
如果我把全局$func_应用;在匿名函数中,它给出了致命错误:函数名必须是…中的字符串。

我使用PHP闭包解决了这个问题:

$func_apply = $_GET['function_name']; // trim | strip_tags | md5 | ucwords

$columns[] = array(
'db'        => $field,
'dt'        => '3',
'formatter' => function( $d, $row ) use ($func_apply) {
            return $func_apply($d);
        }
);

我使用PHP闭包解决了这个问题:

$func_apply = $_GET['function_name']; // trim | strip_tags | md5 | ucwords

$columns[] = array(
'db'        => $field,
'dt'        => '3',
'formatter' => function( $d, $row ) use ($func_apply) {
            return $func_apply($d);
        }
);