1

I have created a model class using Model generator Gii with namespace common\models\Artikel and there is no error but when I'm trying to create a model class using CRUD generator Gii, there is a error like this:

enter image description here

In my Models folder there is folder again named Artikel and then on artikel.php have that namespace common\models\Artikel. But I don't know why I get this error using CRUD generator.

rob006
  • 21,383
  • 5
  • 53
  • 74
Nana
  • 53
  • 3
  • It may be autoloading issue. Can you show this model file in in your project tree and share your autoloading rules in your `composer.json`? – rob006 Feb 20 '19 at 09:19
  • Can you check if in that folder exsist Artikel model and if the file have that namespace – Gabriele Carbonai Feb 20 '19 at 09:32
  • yeah it exist, so in my Models folder there is folder again named Artikel and then on artikel.php have that namespace common\models\Artikel .. but i don't know why its error using CRUD generator @GabrieleCarbonai – Nana Feb 20 '19 at 09:50
  • you "models folder" is in which folder? the file must to be inside common\models folders and not in models\Artikel folders. Are you using base app or advanced one? – Gabriele Carbonai Feb 20 '19 at 10:02
  • if is inside Arkitel folder, is missing the file name. In this case supposing the file Arkitel.php is inside common\models\Arkitel, you must to write in CRUD the structure folder plus file name: common\models\Arkitel\Arkitel – Gabriele Carbonai Feb 20 '19 at 10:07
  • oh im using advance template and i created a Artikel model inside common\models but i remember that when i created models in Model Generator i type **common\models\Artikel** in namespace.. and thats why inside my Models folder there is folder again named Artikel and in that folder there is Artikel.php .. now when i create models in CRUD generator with **common\models\Artikel\Artikel** there is no error again.. @GabrieleCarbonai – Nana Feb 20 '19 at 10:27
  • yes because autoloader was looking for file named Arkitel.php inside models folder – Gabriele Carbonai Feb 20 '19 at 10:29
  • thank you for helping @GabrieleCarbonai – Nana Feb 20 '19 at 10:29

1 Answers1

0

Declaration of this class should be in common/models/Artikel.php and inside of it you should have:

namespace common\models;

class Artikel extends \yii\db\ActiveRecord {
    // ...
}

Artikel Should not be part of the namespace, it is class name.

rob006
  • 21,383
  • 5
  • 53
  • 74
  • ahh i remember when i created models in Model Generator i type **common\models\Artikel** in namespace, so inside models folder there is folder again named Artikel.. and now when i create models in CRUD generator there is no error again because i type **common\models\Artikel\Artikel** .. thank you for remind me about the class name because its my first time using yii2 framework – Nana Feb 20 '19 at 10:28