My dear friends today is the most important days of my lectutre series.
My aim is to create CRUD(Create,Read,Update,Delete) with yii.
I have experiences with many php devolopment frameworks.But Yii is the best and easist one to create CRUD.
It is such easy..
Follow me.
First what I need is a database.
Create a database called 'Data'.
Inside the database we created,create a table using following codes...
Create table infos(Id varchar(20) primary key,
Name varchar(20),
Age int);
Now the table and the database is ok...Now I need to do more configrations.
Step 01...
Open the main.php in protected\config dirctory.....
Step 02 ...
Find the place where you have below codes in main.php
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive,
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
)
Then you have to uncomment it and edit the dbname as data because our database is 'data'.Enter your username and password as you's.But default is as above.
Now my code is as below.
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=data',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
Step 03....
Find the place below place in main.php.
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>your password to access gii,
'ipFilters'=>array('127.0.0.1','::1'),
)
Then uncomment it frist.Give any password to password field in above codes.Now my code is as follows..
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'19891104',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
N.B Yii is an webbase tool in Yii.
Step 04....
Now acess the yii using below codes..
http://localhost/yii/myyii/index.php?r=gii
Here myyii is my Yii project name.If you confused please refer the note in 'Creating Skelton' lesson in this website..
My aim is to create CRUD(Create,Read,Update,Delete) with yii.
I have experiences with many php devolopment frameworks.But Yii is the best and easist one to create CRUD.
It is such easy..
Follow me.
First what I need is a database.
Create a database called 'Data'.
Inside the database we created,create a table using following codes...
Create table infos(Id varchar(20) primary key,
Name varchar(20),
Age int);
Now the table and the database is ok...Now I need to do more configrations.
Step 01...
Open the main.php in protected\config dirctory.....
Step 02 ...
Find the place where you have below codes in main.php
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive,
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
)
Then you have to uncomment it and edit the dbname as data because our database is 'data'.Enter your username and password as you's.But default is as above.
Now my code is as below.
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=data',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
Step 03....
Find the place below place in main.php.
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>your password to access gii,
'ipFilters'=>array('127.0.0.1','::1'),
)
Then uncomment it frist.Give any password to password field in above codes.Now my code is as follows..
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'19891104',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
N.B Yii is an webbase tool in Yii.
Step 04....
Now acess the yii using below codes..
http://localhost/yii/myyii/index.php?r=gii
Here myyii is my Yii project name.If you confused please refer the note in 'Creating Skelton' lesson in this website..
Now insert the password you gave...
And press enter...
You will see the below output.
And press enter...
You will see the below output.
Step 05....
Now I need to creat the model..
To do this click on Model Genarator..
And you will see and output web page.Then fill is as follows..
Enter the table name as infos and modelclass as Info.
Now I need to creat the model..
To do this click on Model Genarator..
And you will see and output web page.Then fill is as follows..
Enter the table name as infos and modelclass as Info.
click on preview and then click on Genarate.
Then go to protected/models and you will see a model called Info.
Step 06....
This is the last step of the prosess.
Now click on CRUD Generator. Enter the model name as “Info”. The controller ID will be auto populated as “info”. This means a new controller will be generated under the name of InfoController.php.
Then go to protected/models and you will see a model called Info.
Step 06....
This is the last step of the prosess.
Now click on CRUD Generator. Enter the model name as “Info”. The controller ID will be auto populated as “info”. This means a new controller will be generated under the name of InfoController.php.
Click on Generate. The process will generate the controller and also several view files with the forms necessary for the CRUD operations.
See in protected\controllers folder you will see InfoController at there..
Now it is ok....
Click on try it now link in the web page and under operations create a new info by clicking it.
The you have to log in to it..
Enter admin as user name and admin as password.
Then click login..
Then add info and click on create.
Enter admin as user name and admin as password.
Then click login..
Then add info and click on create.
Now see the right hand side corner.under Operations do anything what you want....
Try it...
That is really funnnnnnnnnnnnnnnnnnnnnnnnnn :)
Try it...
That is really funnnnnnnnnnnnnnnnnnnnnnnnnn :)