betty
betty

Reputation: 33

Display a master-detail view. yii2

I am looking for some way to implement the following thing with yii2:

Lets imagine we have the following structure: - rawMaterial table. - rawMaterialentry table

Each rawMaterial -> has 1 or more entry.

What I want to do is to display on a view, the details of an rawMaterial, and under it, a gridview of all the entries it has. In some other words, a master-detail view.

My problem is that in the gridview of the Entries, which belongs to the current rawMaterial, when i try to update, view or delete any of the entries it takes me to the rawMaterial instead to the Entry views

Upvotes: 2

Views: 1935

Answers (2)

Double H
Double H

Reputation: 4160

You Have to Change ActionButtonColumn of Your GridView to provide an appropriate Url. Otherwise GridView will use the current contoller.

[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{view}',
'buttons' => [
    'update' => function($url ,$model){
        $url= Yii::$app->urlManager->createAbsoluteUrl(['/entry/update', 'id' => $model->id ]);
        return Html::a('<span class="glyphicon glyphicon-pencil">', $url);
    },
    'view' => function($url ,$model){
        $url= Yii::$app->urlManager->createAbsoluteUrl(['/entry/view', 'id' => $model->id ]);
        return Html::a('<span class="glyphicon glyphicon-eye-open">', $url);
    }
]

]

Upvotes: 0

soju
soju

Reputation: 25322

You should simply set controller in your ActionColumn config.

The ID of the controller that should handle the actions specified here. If not set, it will use the currently active controller.

e.g. :

[
    'class' => 'yii\grid\ActionColumn',
    'controller' => 'entry',
]

Upvotes: 3

Related Questions