Yii Framework Forum: How to define id in ActionColumn - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to define id in ActionColumn [solved]

#1 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 229
  • Joined: 20-April 17
  • Location:Hannover

Posted 31 October 2017 - 03:22 PM

Hi guys,
Following links in ActionColumn(of kartik) works for creating(the last one),but not for updating(one before the last one).
I will get error:
Bad Request(#404)Missing parameter id

actionUpdate in controller needs an id as parameter(probably primary key) but it won't be given. So, my question is: How should I define id in link?


$gridColumn_telefon = [
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{neu_anlegen}<br>{ansicht}<br>{updaten}<br>{erzeugen}<br>{delete}',
        'buttons' => [
            'neu_anlegen' => function ($url) {
                return Html::a('<span class="glyphicon glyphicon-save-file"></span>', $url = 'saveAsNew_telefon', ['title' => 'Duplizieren']);
            },
            'ansicht' => function ($url) {
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url = 'view_telefon', ['title' => 'Anzeigen']);
            },
            'updaten' => function ($url, $id) {
                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url = 'telefon_update', ['title' => 'Bearbeiten']);
            },[b]//this won't work,'cause id will be needed,but it's nowhere defined[/b]
            'erzeugen' => function ($url) {
                return Html::a('<span class="glyphicon glyphicon-road"></span>', $url = 'telefon_create', ['title' => 'Erzeugen']);
            }, [b]//this will work,'cause id won't be needed[/b]
        ],
    ],



Of course, I could determine id in controller,without giving it as parameter, but following code works without defining
id seperatly in link:

    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{save-as-new} {view} {update} {delete}',
        'buttons' => [
            'save-as-new' => function ($url) {
                return Html::a('<span class="glyphicon glyphicon-copy"></span>', $url, ['title' => 'Save As New']);
            },
        ],
    ],


P.S.: I have two independent tables in one GridView
0

#2 User is online   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 145
  • Joined: 10-October 11
  • Location:Russia

Posted 31 October 2017 - 05:17 PM

https://github.com/y...nColumn.php#L82
0

#3 User is offline   tklustig 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 229
  • Joined: 20-April 17
  • Location:Hannover

Posted 05 November 2017 - 02:36 PM

View Postumneeq, on 31 October 2017 - 05:17 PM, said:



I got it. It's according giving informations of link uppon:

$gridColumn_telefon = [
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => '{view_telefon}<br>{update_telefon}<br>{neu_anlegen}<br>{delete}',
        'buttons' => [
            'view_telefon' => function ($url, $id) {
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, ['title' => 'Anzeigen']);
            },
            'update_telefon' => function ($url, $id) {
                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Bearbeiten']);
            },
            'neu_anlegen' => function ($url, $id) {
                return Html::a('<span class="glyphicon glyphicon-save-file"></span>', $url, ['title' => 'Duplizieren']);
            },
        ],
    ],

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users