Yii2 - Error when trying to run code created by Gii

Hi,

I am trying to create the model, controller, and views using gii, but get the following error when trying to run code created by Gii doing the following steps

  1. run gii and creating the model for a table in my database using the Model Generator option

  2. next creat the controller and vies using the crud Crud Generator Option

  3. try and access the newly created code

The error is as follows:

Unknown Class – yii\base\UnknownClassException

Unable to find ‘backend\controllers\CollectionController’ in file: C:\wamp\www\bam/backend/controllers/CollectionController.php. Namespace missing?

Any help with this would be greatly appreciated.

Thank you,

Lloyd

Problem Solved

It turns out that the namespace command was wrong

  • namespace app\controllers; should have been namespace backend\controllers;

When using gii with advanced template, make sure that you enter the correct information when creating

the controller class using the gii crud generator option

Hope this helps someone else with the same error

1 Like