Question

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.

Was it helpful?

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

OTHER TIPS

It sounds like you are trying to modify production code in your live production environment. What happens when you do something to break the site? How long can that site afford to be off-line, or have things not working quite right? It is my experience that new development should be done in a development environment and then promoted to production. Otherwise you are forced to test your changes in your live production environment, and that is a dangerous thing indeed.

Given that you are new to Yii, odds are that you aren't going to be able to write code that is bug free the first time.

Best thing to do is create a development environment to mirror production, and install Gii there. Then you can create all the models and controllers you want with Gii, test your changes, and finally promote your changes to the production environment. This is really a best practice issue. You don't want to be changing your live code with untested code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top