It seems that I have to change the view files and I don’t know why? I used Gii to generate the models and CRUD…
My view file “index.php” for Users has:
‘urlCreator’ => function ($action, Users $model, $key …
And I have to change it to
‘urlCreator’ => function ($action, \app\models\Users $model, $key
How to I prevent having to change every view file? so I can use “Users $model” instead of “\app\models\Users $model” ?
also you can import the Users class with a use expression, normally at the top of the file.
It seems that the Gii template you’re using is not using the fully name of the class when generating the code. So, you can modify the template OR do the change manually every time.
I guess I am confused as to why something needs to be changed. When I used Gii to create CRUD, why do I need to edit any of the files for them to work?
At the bottom of the gridview section in the index.php view in the urlCreator I see…
‘urlCreator’ => function ($action, Schools $model, $key, $index, $column) {
return Url::toRoute([$action, ‘school_id’ => $model->school_id]);
It won’t work if I navigate to the Schools index view unless I change it to …
‘urlCreator’ => function ($action, app\models\Schools $model, $key, $index, $column) {
return Url::toRoute([$action, ‘school_id’ => $model->school_id]);
My yii2 was just installed using composer so it should be up to date. Why is this happening and why do I need to alter the template for this to work?