我正在維護一個帶有模型和子記錄網格的表單。我想讓網格顯示孩子的網址,而不是父網址。yii2更改gridview模型
我有兩個共享父子關係的數據庫表。我只展示了重要的領域。
describe ops;
+---------------+--------------+
| serial_number | int(11) |
+---------------+--------------+
describe opsitem;
+---------------+--------------+
| opsitem_id | int(11) |
| ops_id | int(11) | # foreign key
| serial_number | int(11) |
+---------------+--------------+
在我的控制,我顯示行動形式,然後爲孩子記錄創建一個ActiveRecord - Opsitem
class OpsController extends Controller
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->ops_id]);
} else {
$searchModel = new OpsitemSearch();
$dataProvider = $searchModel->search(
['OpsitemSearch' => ['ops_id' => $model->ops_id]]
);
return $this->render('update', [
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
}
我的表單包含OPS(父),然後將含有一格表單字段oppsitem(子)記錄在網格上的「更新」按鈕
// $model is Parent - Ops
<?php echo $this->render('_form', [
'model' => $model,
]) ?>
// $searchModel is Opsitem - Child
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'ops_item_id',
'ops_id',
'serial_number'
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
],
]); ?>
點擊指向我url
:
/OPS /更新?ID = 1234
我想
/opsitem /更新?ID = 1234
謝謝。我在文檔(http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html)中看到它(現在),但不會發現它。 – crafter