I have a gridview with the code bellow and I have the error Illegal string offset ‘id’
at
$url = Url::to(['site/archive', 'param' => $param,'pl'=>data['id']]);
how can I fix it?
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
// 'name',
[ 'attribute'=>'name',
'class' => 'yii\grid\DataColumn', // can be omitted, as it is the default
'format'=>'html',
'value' => function ($data) {
$url = Url::to(['site/archive', 'param' => $param,'pl'=>data['id']]);;
return Html::a($data['name'], $url) ; // $data['name'] for array data, e.g. using SqlDataProvider.
},
],
]
]);
the controller
$count = Yii::$app->db->createCommand('SELECT COUNT(*) FROM plans')
->queryScalar();
$dataProvider = new \yii\data\SqlDataProvider([
'sql' => 'select id,name from plans order by name',
'totalCount' => $count,
'key' => 'id',
'sort' => [
//'defaultOrder' => ['name' => SORT_DESC,],
'attributes' => [
'name',
]],
'pagination' => [
'pageSize' => 50,
]
]);
[Edit]It is a typo error data[‘id’] must be $data[‘id’]