Google Ads

Introduction To YII Framework PHP Script


Introduction To YII Framework PHP Script

There are lot of PHP framework available these days. I this tutorial I am going to introduce YII framework which is one of the popular php framework. YII is a component base php framework that is used to build large scale web application since it is known to be one of the high performance php frameworks available today. Yii is simple to learn and contained richest fractures make high complex web applications

Requirement

1 php 5.10 or higer
2 knowledge of object oriented programming in php (MVC design pattern )

Installation

1 . First you need to download files from yii framework web site
2 . Then unzip yii folder and copy to your web server www directory

After you copied file navigate to yii/requirements/index.php through you browser. This link will be listed all the requirement you need to have run yii application.

How create a web application.

After you have successfully installed yii in your web server, you can use YIIC ( YII framework command line tool ) tool to create new web application . It is very easy to create initial web application using yii tool which provides all the needed file and initial configuration to web application
Command that I used to create my xdata application is as follows

 

 
 
  1. C:\wamp\www\ - > framework/yiic xdata c:\wamp/www/testdrive

 

framework/yiic = path to my yiic tool
xdata = my application name
c:\wamp/www/testdrive = where I want to create application

If you are able to run the command successfully you can see the our xdata application has been created on web server with all wanted files and structure to run initial web application.

How to connect to database

Go to the xdata/protected/config/main.php and find the db array and placed the data base configuration in to code line that describe as DB. Xdata example as follows

 

 
 
  1. 'db'=>array(
  2. 'connectionString' => 'mysql:host=localhost;dbname=sence_data',
  3. 'emulatePrepare' => true,
  4. 'username' => 'root',
  5. 'password' => '',
  6. 'charset' => 'utf8',
  7. ),

 

Crating a crude operation

Creating a crude operation in yii is very easy. Yii has code generation tool called gii which can be used to created all crude operation you need. To configure gii you need to give a user name and password to gii code section of config.php file. My xdata application gii configuration as follows.

 

 
 
  1. 'gii'=>array(
  2. 'class'=>'system.gii.GiiModule',
  3. 'password'=>'abc',
  4. // If removed, Gii defaults to localhost only. Edit carefully to taste.
  5. 'ipFilters'=>array('127.0.0.1','::1'),
  6. ),

 

 

Using gii tool you can create all the crude operation and needed file structure to run higly capable aof application in a very short time. Please refer yii documentation for more details of gii

 

 

Have any Question or Comment?

Leave a Reply

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

"