Search code examples
yiicrudgii

Crud for existing model in YII


I am trying to create CRUD for my model classed generated automatically by GII.

Classes are stored like models/entity/Article.php. When i try to Gii generator put as class name models.entity.SomeClass or entity.SomeClass it doesn`t work.

The gii stops with exception Alias "entity.Article" is invalid. Make sure it points to an existing directory or file.

How can I run CRUD script properly?


Solution

  • Set the alias in your config/main.php file (do this before the return array):

    Yii::setPathOfAlias('entity',dirname(__FILE__).DIRECTORY_SEPARATOR.'../models/entity');
    
    // rest of config
    return array(
        // ...
    );
    

    Then use entity.Article in gii.