How to set special parameter in anonymous function?

Hi guys,

in my actual modul, records of database can be deleted in two different ways:

Once anbout checkBoxes, Second about BootstrapIcon. Giving parameter in first version isn’t a problem. Parameter comes from Controller like this





    public function actionIndex($id, $FKBezeichnung) {

        $searchModel = new DateianhangSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id, $FKBezeichnung);

        return $this->render('index', [

                    'searchModel' => $searchModel,

                    'dataProvider' => $dataProvider,

                    'id' => $id,

                    'FKBezeichnung' => $FKBezeichnung

        ]);

    }

.

.


?><?=

Html::beginForm(['/dateianhang/dateianhang/all', "RenderBackInCaseOfError" => $RenderBackInCaseOfError, "FkBezeichnung" => $FKBezeichnung, 'fk' => $id], 'post', ['name' => 'idAnhang']);



My question:

How to implement parameter [size="2"]$FKBezeichnung in anonymous function,which will delete one single record like this[/size]

[size="2"]




[ 'class' => 'yii\grid\ActionColumn',

'template' => '{view} {update} {delete_records}', 

'buttons' => [ 'delete_records' => function ($url, $model) { 

$RenderBackInCaseOfError = "/dateianhang/dateianhang/index_without_id"; 

$FKBezeichnung = "id_person"; 

return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/dateianhang/dateianhang/del', 'id' => $model->id, 'RenderBackInCaseOfError' => $RenderBackInCaseOfError, 'FKBezeichnung' => $FKBezeichnung], ['title' => 'Löschen', 'data' => ['pjax' => '0']]);

 },   	

 ] ]



[/size]

[size=“2”]As U can see, parameter [/size][size=“2”]$FKBezeichnung is hard coded. That’s bad,'cause other moduls have no ForeignKey like this. So, I need to set this parameter in anonymous function! I could use PHP-function [/size][color="#333333"] mysql_field_name(). What is yii2 expresison of this function?[/color]

Solved problem by my own. Here is code:





    [

        'class' => 'yii\grid\ActionColumn',

        'template' => '{view} {update} {delete_records}',

        'buttons' => [

            'delete_records' => function ($url, $model) {

                $IdEDateianhang = EDateianhang::findOne(['id' => $model->id_e_dateianhang]);

                $attributesOfTable = $IdEDateianhang->attributes;

                foreach ($attributesOfTable as $attribute => $ValueOfAttribute) {

                    if ($ValueOfAttribute != NULL && $attribute != "id")

                        $FKBezeichnung = $attribute;

                }

                $RenderBackInCaseOfError = "/dateianhang/dateianhang/index_without_id";

                return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/dateianhang/dateianhang/del', 'id' => $model->id, 'RenderBackInCaseOfError' => $RenderBackInCaseOfError, 'FKBezeichnung' => $FKBezeichnung], ['title' => 'Löschen', 'data' => ['pjax' => '0']]);

            },

        ]

    ]



This thread can be closed as succesfully solved

Actually many examples in yii2 core script, like this:




$outVar = 'Indonesia';

$resFromFunc = function() use ($outVar) {

    return $outVar;

};