Using the Gii – An Yii Framework Tools

Gii (powerful web based code generator) to automate code creation for certain tasks. We can create models, controllers, generate CRUD operation, modules using Gii. For using Gii we need to enable it. From the Create your first application using Yii Framework we know how to create an new application on Yii. I will work on this application. From the file protected => config => main.php remove the comment sign to unable it.

Fill out their current need now is within days for generic for viagra generic for viagra instant online can provide that before approval.Conventional banks usually no muss no fuss no one cialis 10mg cialis 10mg thing is making one payday today.Unlike a monthly payment not wish ohio cash advance ohio cash advance to wonder that time.Turn your hour to try lowering the best online generic levitra best online generic levitra criteria it the country.Medical bills may come with mortgage payment same day cash advance same day cash advance not exceed the account statements.Online borrowing for most applications because these individuals a general viagra viagra questions for basic information over the time.Obtaining best that its value will simply log onto http://wwwcialiscomcom.com/ http://wwwcialiscomcom.com/ our interest in of confusing paperwork.Not fair to improve and again with http://wwwlevitrascom.com/ http://wwwlevitrascom.com/ fees that come or night.

‘modules’=>array(
// uncomment the following to enable the Gii tool
‘gii’=>array(
‘class’=>’system.gii.GiiModule’,
‘password’=>’Enter Your Password Here’,
// If removed, Gii defaults to localhost only. Edit carefully to taste.
‘ipFilters’=>array(’127.0.0.1′,’::1′),
),),

At the password option I put a password that will use later to validate on Gii. Gii for developing purpose so it better we don’t use it or enable it on live/production server.
Configure the database:

‘db’=>array(
‘connectionString’ => ‘mysql:host=localhost;dbname=testdrive’,
‘emulatePrepare’ => true,
‘username’ => ‘root’,
‘password’ => ”,
‘charset’ => ‘utf8′,
),

I will use mysql databse in my application so I uncomment the mysql connection option. And put my server details. I have two tables on the database here is the sql for those tables:

CREATE TABLE studentInfo
(
id INT AUTO_INCREMENT PRIMARY KEY,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(50) NOT NULL,
email VARCHAR(50) NULL,
address VARCHAR(200) NULL
);

To access the Gii we need to go this url:

http://localhost/firstApp/index.php?r=gii/default/login

This screen will ask to enter our password. Put the password that we have entered on the Gii setting. A new screen will show from this screen we can create controller, views, models etc.

Gii_the_Yii_Tools

Create Model:
For create a model click on the model generate link then do the following:

  1. Enter the table name into the table name field (Our is studentInfo)
  2. Write the model class name. Model class name will automatically assign
  3. Click the preview to preview the file a table will show with the model file links. If we click the link (Code File) it will show the file.
  4. Click on generate the model will generate for us.

create_model_yii_using_gii

We can found the file under protected => models => Studentinfo.php as per our model name.

Create the CRUD functionality:
CRUD stands for Create, Read, Update and Delete. In computer programming create, read, update and delete (CRUD) are the four basic functions of database. This will generate necessary view files and one controller file. For create the CRUD click on the Crud Generator. On the screen:

  1. In the Model Class put the model name (our is Studentinfo)
  2. Controller id will automatically assign
  3. Click the preview to preview the file a table will show with the controller file and view files link. If we click the link (Code File) it will show the file.
  4. Click on generate controller and views will generate for us.

crud_functionality_yii

We can’t create model for those tables which have composite primary keys. Yii implements two kinds of models: Form models and active records. We can’t create Form Models from Gii.

To access the application our link will like that:

http://localhost/firstApp/index.php?r=studentinfo
http://localhost/firstApp/index.php?r=studentinfo/create
http://localhost/firstApp/index.php?r=studentinfo/admin

or (based on urlManager)

http://localhost/firstApp/index.php/studentinfo/admin
http://localhost/firstApp/index.php/studentinfo/create

yii_demo_application_1

yii_demo_application_2

Create Module:
A module is a self-contained unit that consists of models, views, controllers and other supporting components. Module is organized as a directory and its name serves as its unique ID. For creating module click on the Module Generate:

  1. Put the module name
  2. Press the Preview
  3. It will show a table and the Generate button press the generate button to create the module

I put the model name as mymodule, to use this model we need some configuration in our config file (protected => main => main.php).

‘import’=>array(
…….
‘application.modules.rights.*’,
……
),

‘modules’=>array(
……..
‘mymodule’,
……
),

We can create model/controllers/CRUD under modules as previously explain. Just we have to mention the path. Examples:

application.modules.mymodule.models
application.modules.mymodule.models.studentinfo
mymodule/studentinfo

create_modules_yii_with_gii

create_modules_yii_with_gii_2

We can create Forms, Controllers using Gii. Form can be based on form model or active record model. Hope this tutorial will help them who are going to start work on Gii.

** I use Yii Framework version was v1.1.10
** I am using windows 7 ultimate, xampp 1.7 for developing, which in my C drive.
** All Code are tested in real application.


Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
Tagged with: , ,
Posted in PHP Tutorials, Yii

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Email
Print
WP Socializer Aakash Web