This tutorial is all about the CRUD genaration of the Yii.
I have used CI,Cake PHP but the Yii one is the framework that I saw,which is nice and quick to create CRUD.
What is CRUD??
It is stands for Create,Retrive,Update and Delete.
Now let us start the journey…
In Yii there is a web tool called Gii to do this CRUD applications easily.
Follow me…
Step 01->
Create a working Yii project.
Step 02->
First of all create a database using phpmyadmin called ‘mydata’.
Then create a table using below query.
Create table infos(Id varchar(20) primary key,
Name varchar(20),
Age int);
Step 03->
Now what you want to do is to do some modifications in your documents.
Open database.php in /config
Find the below code
/*
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
*/
And replace the above code from the below set of codes.
‘connectionString’ => ‘mysql:host=localhost;dbname=mydata’,
‘emulatePrepare’ => true,
‘username’ => ‘root’,
‘password’ => ‘’,
‘charset’ => ‘utf8’,
Step 04->
Open main.php in /config
Find the below code
/*
'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'),
),
*/
Replace it from below code.
‘gii’=>array(
'class'=>'system.gii.GiiModule',
'password'=>'19891104', //Enter any password to log in to yii CRUD.
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
Step 05->
Now it has come to the last step.
Log in to the CRUD generator using
http://localhost/yii/myyii/index.php?r=gii
N.B Here myyii is the name of my yii project.
Step 05->
Now enter the password(19891104) and log in to the code generator of Yii.
Click on model generator and enter the name of the table as infos and the name of the model class as Info.
Click on preview and click on generate.
See the models folder in /protected you will that the model called ‘Info’ has created.
Step 06->
Click on Crud Generater link and add model class as Info and Controller ID will autimatically will fill.
Click on preview and generate it.
Now find the link ‘try it now’ in the same interface. Click on it.
Now click on Create Info under Operations.
Step 07->
Then you have to log in to it…
Enter admin as user name and admin as password.
Step 08->
That is all and play with it.
See how data will store in the database.
Be Happy…