Search code examples
yiigii

Create new model in Yii without using Gii


I'm new to Yii and am taking over maintenance of a fairly completed project. In all the books and web resources it only talks about adding new models/controllers etc using the Gii tool. I have looked in the config/main.php file of this project and the Gii module has been removed and also there is no index.php page for me to simply re-add it to. The project is live on a server already.

How do I add a new model to the site? I have tried duplicating an existing model and creating a new database table but I can't seem to access it from anywhere within the app. Would I also have to edit a file in the framework somewhere to add a new reference to this model?

Or do I have to create a local development environment replica of the site and use gii there, then add the new files (presumably not just the model file otherwise what's the difference?) to the server.


Solution

  • Gii model generator just create file in Model folder, so you just need to duplicate one of them and change all references.

    If you create some different from other models class in that folder it will work, because of autoloader.

    Probably you just forgot to change some info. Check file name. It need to be EXACT same as class name. For example if your model class name is Users your file need to be Users.php