Oh my God ! What a strange title !! Well, don’t be afraid. If you been following the other Yii tips this one is going to be easier.

Let’s assume you’ve installed Wamp and let’s assume you’ve installed Yii either and that you’ve created your first webapp using the Yii command line (yiic webapp).

Now, I assume here that you’ve created a database and that you have some tables in it (if not, there are plenty of samples down the Web. Just Google it !)

As you know now, if you’ve read all the other posts about Yii, you must un comment the db part of the Yii’s configuration file (in protected/config/main.php). So you will have to put the connect string of your database using the db’s credentials.

When done, your Yii webapp is now tied up to a database.

We are going now to use a Yii tool to generate (not so) basic CRUD (CReate, Update, Delete) views on the tables of your database.

Believe me, this is the best start for your webapp. This operation is called : scaffolding.


Gii is the generator that comes along with Yii. To be able to use it you must head to your webapp configuration file and un comment the following paragraph.

// uncomment the following to enable the Gii tool

			'password'=>'a pwd',
		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.

The password must not be empty, otherwise Gii won’t let you in !

Now go to your browser and type the url of your webapp withe following parameters.


You will be prompted to enter the password you put in the configuration file.

First thing we will have to do is to create the yii models of your tables. In the model field, just enter the name of your table.



By clicking on preview, Gii will show youthe file it’s going to generate. Just generate the model and head to the next step.

Click on CRUD generator. There, you will have to enter the name of the model that you’ve just generated.


Click on preview and Gii will show the files that are going to be generated (controller and views). Go on, generate the files.


By the end of the process, Gii will give you the urls to the newly created views.

Go there. If you click on manage you will be asked for a login password. That’s the default protection that Yii puts in place when generating the app. The default login/password is “admin/admin“.

Just navigate to your newly created views or go on using Gii for you other tables. Explore the generated code in your editor as well. that is the best way to learn how Yii works. The generated files can be found in the protected folder inside controllers, models and views sub folders.

See you