使用KartikExpandRowColumnWidget在折叠的行中显示数据,我希望按特定记录的ID显示数据,
动作索引()
public function actionIndex() {
$searchModel = new CreateBookingsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$model = new CreateBookings();
$data = CreateBookings::findOne($id);
if (Yii::$app->request->post('hasEditable')) {
$id = Yii::$app->request->post('editableKey');
$model = CreateBookings::findOne($id);
$out = Json::encode(['output'=>'', 'message'=>'']);
$posted = current($_POST['CreateBookings']);
$post = ['CreateBookings' => $posted];
if ($model->load($post)) {
$model->save();
$output = '';
}
echo $out;
return;
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
'data' => $data,
]);
}
局部视图:
<?php echo Html::encode($data->check_in);?>
<?php echo Html::encode($data->check_out);?>
网格视图
'columns' => [
[
'class' => 'kartik\grid\ExpandRowColumn',
'value' => function ($model,$key,$index,$column) {
return GridView::ROW_COLLAPSED;
},
'detail' => function ($model,$key,$index,$column) {
$searchModel = new CreateBookingsSearch();
$searchModel->booking_id = $model ->id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Yii::$app->controller->renderPartial('_expandrowview.php',[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
},
],
在索引中传递$data = CreateBookings::findOne($id);
时出现错误Undefined variable: id
。我需要类似于public function actionView($id)
的内容作为索引public function actionIndex($id)
需要在索引中传递id
2条答案
按热度按时间3phpmpom1#
您可以尝试此操作(使用detailUrl)
在网格视图中(在任意位置添加列)
此处:detailUrl将是格式为../controllerName/expandView的URL
在控制器中
bz4sfanl2#
很抱歉,我使用基于视图的模型,并且$_POST ['expandRowKey']始终返回NULL。