我正在尝试使用kartik expandrow。 在PartiesSearch模型的第一级查询是 -
$query = (new Query())->select(['district'])->from('districts');
在ExpartiesSearch Model中的第二级查询是 -
$query = (new Query())->select(['parties_district','parties_partyname'])->from('parties');
index.php中expandrow的代码是 -
[
//['class' => 'yii\grid\SerialColumn'],
'class' => 'kartik\grid\ExpandRowColumn',
'value' => function($model, $key, $index, $column){
return GridView::ROW_COLLAPSED;
},
'detail' => function($model, $key, $index, $column){
$searchModel = new ExpartiesSearch();
$searchModel-> parties_district = $model-> district;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Yii::$app->controller->renderPartial('_exparties', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
},
],
我收到错误 -
Trying to get property of non-object
突出显示的错误行是 -
$searchModel-> parties_district = $model-> district;
如果我将PartiesSearch Model中的查询更改为
,则同一段代码可以正常工作$sql = 'select district from districts';
$query = Districts::findBySql($sql);
但是,我必须以特定格式(从查询生成器派生)编写查询。请帮忙。
答案 0 :(得分:1)
在我的测试中:
$query = (new Query())->select(['district'])->from('districts');
将返回数组数组。在这种情况下,您需要使用$ model ['district']。
[
//['class' => 'yii\grid\SerialColumn'],
'class' => 'kartik\grid\ExpandRowColumn',
'value' => function ($model, $key, $index, $column) {
return GridView::ROW_COLLAPSED;
},
'detail' => function ($model, $key, $index, $column) {
$searchModel = new ExpartiesSearch();
$searchModel->parties_district = $model['district'];
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Yii::$app->controller->renderPartial('_exparties', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
},
尝试使用xdebug查看$ model中的确切内容