We hear a lot about all different frameworks for PHP. Here I have tried to show you the quickest way to create an Yii web application using the in-built tools that Yii provides. This can be done in just 4 steps as follows:

Now that we have the source for YII. Its time to now create our first Yii Application. There are two ways to do that. One is creating all directories and files manually. Why do something manually if you get it done automatically? You can use yiic command to do that through command line.

Step2: Extract the downloaded zip in your project directory. yii provides a yiic command for creating web application and most of the code is automatically generated. Run the following command in command prompt in case of windows or in terminal in case of LINUX.

1

%YiiRoot/framework/yiic webapp WebRoot/testapp

This command creates a skeleton application under the web root directory named testapp. Once you have run the above command, you can view this application by visiting http://hostname/testapp/index.php

Easy as you like. Only two steps and you already have a web skeleton. Now lets connect this application to a database.

Step 3: To use the database we need to open the file main.php under the directory config. Uncomment db array and enter relevant database settings as shown below

PHP

1

2

3

4

5

6

7

'db'=>array(

'connectionString'=>'mysql:host={hostname};dbname=dbname',

'emulatePrepare'=>true,

'username'=>'username',

'password'=>'password',

'charset'=>'utf8',

),

Step 4: Now that we have database connection, we can start creating various modules and pages. How do you do that? Same again there is automated tool to do that. This is called gii tool. Edit the main.php and uncomment the following:

You can visit http://hostname/testapp/index.php?r=gii for accessing the code generator. As you will notice, there are options to create a lot of things like CRUD, Models etc. You can try exploring each of the options given there. Happy code-yii-ing 🙂