Zii grids are very useful to quickly create efficient application admin pages or any pages on which you need to manage data.
Let's use Gii to generate a grid, see how it works, and how we can customize it.
Carry out the following steps:
Create a new application using
yiic webapp
as described in the official guide.Download the Sakila database from http://dev.mysql.com/doc/index-other.html. Execute the downloaded SQLs (first schema then data).
Configure the database connection in
protected/config/main.php
.Use Gii to create models for the
customer
,address
, andcity
tables.
Open Gii, select Crud Generator, and enter
Customer
into the Model Class field. Press Preview and then Generate.Gii will generate a controller in
protected/controllers/CustomerController.php
and a group of views underprotected/views/customer/
.Run the
customer
controller and go to the Manage Customer link. After logging in you should see the grid generated, as shown in the following screenshot...