What is Gii and how to use it
In this post I will try to explain what is Gii tool, and how to use it to speed up your development.
You decided to develop your web application using Yii framework. You have already designed your database and you have created database tables and relations. This is a good starting point, but what is the next step.
The first thing you have to enable is Gii tool. Gii tool is separate module in Yii framework which enables your to automatically generate database models, CRUD operations, modules, and controllers.
Here is definition of every term:
Models – Model is a PHP class that maps data from a database into PHP objects. This enables you to perform select, insert, update and delete sql queries in object oriented way.
CRUD – Create Read Update Delete – In few clicks you can create all this actions for every database table. Remember how much time you would spend doing this things, manually, and here you can do it in few clicks.
Modules – A module is a self-contained software unit that consists of models, views, controllers and other supporting components. In many aspects, a module resembles to an application.
To enable Gii module, open your
main.php configuration file (
protected/config/main.php), and uncomment the following lines:
// uncomment the following to enable the Gii tool
// If removed, Gii defaults to localhost only. Edit carefully to taste.
In the code above you can define a Gii password, which you will need in order to access Gii functionalities.
If you are working on your local machine, then you can leave ipFilters field as is, but if you want to enable someone to access Gii on your server then you can define multiple IP addresses (‘192.168.1.2′,’192.168.1.2’), or IP address with wildcard to represent network segment (‘192.168.1.*’). If you want to disable ipFilter, then set this property to false.
To run Gii tool, run one of the following links (the exact format depends on Yii’s URL configuration and your localhost path):
When you start Gii tool, you should the following page should be displayed:
When you enter your Gii’s password, you will be redirected to the Gii’s dashboard:
To create a new model, just click Model Generator option, and new page will appear.
In Table Name field enter a name of a database table, and click preview. Gii will show you which files is going to be created. Confirm by clicking on Generate button, and hoa, your first model file is generated.
Generated module class can be used to retreive data from database, or to store data to database. If you have generated User model, from the database table called user, then you can do something like this:
$allUsers = User::model()->findAll();//Get all users from user table
//Create a new row in database
$user = new User();
$user->firstName = "John";
$user->save();//Save user in database
Hope I helped.
http://code-epicenter.com/what-is-gii-and-how-to-use-it/What is Gii and how to use itPHPProgrammingTutorialsUncategorizedGii,PHP,Yii frameworkIn this post I will try to explain what is Gii tool, and how to use it to speed up your development. You decided to develop your web application using Yii framework. You have already designed your database and you have created database tables and relations. This is a good...Amir DuranAmir Duranamir.firstname.lastname@example.orgAdministratorAmir Duran is software engineer who currently lives and works in Germany. He obtained Masters degree diploma on Faculty of Electrical Engineering in Sarajevo, department Computer science. With good educational background he is specialized in designing and implementing a full-stack web based applications.Code Epicenter