sending id in link about anonymous function

Hi guys, a simple question:

Is it possible in yii sending any value of model by link to another script,which is in another folder?

I use following code calling attachements from model bewerber





 	[

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

            'template' => '{anlagen_index}',

            'buttons' => [

                'anlagen_index' => function ($url) {

                    return Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/index'], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]);

                },

            ],

        ],



Is it possible,that Primary Key of bewerber will be given to Controller of dateianhang, for instance like this

[size="3"]


[


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

            'template' => '{anlagen_index}',

            'buttons' => [

                'anlagen_index' => function ($model,$id) {

                    return Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/index'], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]);

                },

            ],

        ],

[/size]

[size="3"]If I try like this, I will get error(in CRUD dateianhang):[/size]

[size="3"]


Bad Request (#400)missing parameter: id 

[/size]


'buttons' => [

    'anlagen_index' => function ($model,$id) {

        return Html::a('', ['/dateianhang/dateianhang/index', 'id' => $id], []);

    },

],

Great. Thx al lot. But I want more

Unfortunately, i just can give PrimaryKey of model as parameter. Any ideas,how to set a special ForegnKey -let’s say id_person- as parameter?

Got it. If I code like this, foreignKey will be given as parameter,too!





      [

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

            'template' => '{anlagen_index} <br>{anlagen_create} ',

            'buttons' => [

                'anlagen_index' => function () {

                    return Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/index'], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]);

                },

                'anlagen_create' => function ($model,$id) {

                    return Html::a('<span class="glyphicon glyphicon-paperclip"><span class="glyphicon glyphicon-plus"></span>', ['/dateianhang/dateianhang/create','id' => $id->id_person], ['title' => 'Anlage erzeugen']);

                },

            ],

        ],

That’s really fantastic. It’s a small step for mankind, but a big one for programmers world

Now, I can use ForeignKey in order to create attachement(s) for every model. Attachements will be used by m:n cardinality, which is dissolved by table e_dateianhang

Controller in dateianhang looks like this:





    public function actionCreate($id) { //$id contains FK of bewerber

        $model = new Dateianhang();

        $model_e = new EDateianhang();

        if (!$model || !$model_e) {

            throw new \yii\base\NotSupportedException(Yii::t('app', 'Die Tabellen dateianhang oder e_dateianhang konnten nicht geladen werden'));

        }

        $behavior = new \common\wsl_components\Wsl_Blameable_Behavior();

.

.

.



This thread can be closes as succesfully solved. Special thx for umneeq of Russia!!