类型错误 Yii2 框架
TypeError Yii2 Framework
yii\base\View::{closure}(): 参数 #2 ($model) 必须是 Libro 类型,app\models\Libro given
在 C:\xampp\htdocs\biblioteca\views\libro\index.php
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'titulo',
'imagen',
[
'class' => ActionColumn::className(),
* 'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
将您的闭包更改为:
'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
进入:
'urlCreator' => function ($action, \app\models\Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
In other words, use right class as type (\app\models\Libro
instead of Libro
).
在脚本开头包括以下行以及其他使用语句:
use app\models\Libro;
yii\base\View::{closure}(): 参数 #2 ($model) 必须是 Libro 类型,app\models\Libro given
在 C:\xampp\htdocs\biblioteca\views\libro\index.php
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'titulo',
'imagen',
[
'class' => ActionColumn::className(),
* 'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
将您的闭包更改为:
'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
进入:
'urlCreator' => function ($action, \app\models\Libro $model, $key, $index, $column) {*
return Url::toRoute([$action, 'id' => $model->id]);
}
In other words, use right class as type (
\app\models\Libro
instead ofLibro
).
在脚本开头包括以下行以及其他使用语句:
use app\models\Libro;