使用Kartik展开行列小部件显示折叠行中的数据,我想按特定记录的ID显示数据,
的actionIndex()
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);?>
的GridView
'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,
]);
},
],
在索引中传递Undefined variable: id
时收到错误$data = CreateBookings::findOne($id);
。我需要public function actionView($id)
之类的索引public function actionIndex($id)
需要在索引中传递id
答案 0 :(得分:0)
你可以尝试这个(使用detailUrl)
在Gridview中(在任何地方添加列)
.
.
'ExpandRowColumn'=>
[
'class' =>'\kartik\grid\ExpandRowColumn',
'value'=>function ($model, $key, $index,$column) {
return GridView::ROW_COLLAPSED;
},
'detailUrl'=> Yii::$app->request->getBaseUrl().'..../expand-view',
],
.
.
这里:detailUrl将是../ controllerName / expandView
格式的URl控制器中的
public function actionExpandView()
{
if(isset($_POST['expandRowKey'])) {
$model = ModelName::findOne($_POST['expandRowKey']);
$variable= $anydata; //anydata want to send in expanded view
return $this->renderPartial('_expandrowview.php',['anydata'=>$anydata,'model'=>$model]);
}
else
{
return '<div class="alert alert-danger">No data found</div>';
}
}
>>>expandRowKey is the first_column_data(may be id) of your model or table
*** you can send anydata using this method and can fetch data using simple php
print_r($anydata); code
on _expandrowview.php (view file) to make changes according to need..
答案 1 :(得分:0)
对不起,但是 我使用基于View的模型,并且$ _POST ['expandRowKey']始终返回NULL。