1

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

]); ?>

1
  • 1
    Error message says "must be of type Libro, app\models\Libro given". So, I guess you are in "app\models" namespace, so use \Libro $model or use Libro; after your namespace statement. Commented Jan 7, 2022 at 20:34

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

use app\models\Libro;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.