Skip to content
Advertisement

TypeError Yii2 Framework

yiibaseView::{closure}(): Argument #2 ($model) must be of type Libro, appmodelsLibro given

in C:xampphtdocsbibliotecaviewslibroindex.php

'filterModel' => $searchModel,
'columns' => [
    ['class' => 'yiigridSerialColumn'],

    'id',
    'titulo',
    'imagen',
    [
        'class' => ActionColumn::className(),
     *   'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
            return Url::toRoute([$action, 'id' => $model->id]);
         }
    ],
],

]); ?>

Advertisement

Answer

Change your closure from:

'urlCreator' => function ($action, Libro $model, $key, $index, $column) {*
    return Url::toRoute([$action, 'id' => $model->id]);
}

Into:

'urlCreator' => function ($action, appmodelsLibro $model, $key, $index, $column) {*
    return Url::toRoute([$action, 'id' => $model->id]);
}

In other words, use right class as type (appmodelsLibro instead of Libro).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement