Enrique
Enrique

Reputation: 13

TypeError Yii2 Framework

yii\base\View::{closure}(): Argument #2 ($model) must be of type Libro, app\models\Libro given

in 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]);
         }
    ],
],

]); ?>

Upvotes: 1

Views: 3086

Answers (2)

Senthil
Senthil

Reputation: 644

Include below line at the beginning of the script along with other use statements:

use app\models\Libro;

Upvotes: 0

Top-Master
Top-Master

Reputation: 8816

Change your closure from:

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

Into:

'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).

Upvotes: 2

Related Questions