Yii and Bootstrap – YiiStrap: How to Install and Configure

Simple steps to help you get started with YiiStrap.

  1. Install Yii.
  2. Create a new Yii application.
  3. Copy YiiStrap.
  4. Change configuration.
  5. Use Gii: Automated Code Generation.
  6. Create CRUD using Gii

Install Yii

  1. Download the latest Yii Framework from here: http://www.yiiframework.com/download/
  2. Unzip it into your htdocs or www or public_html folder. Basically unzip it into a browse-able location.
  3. You need only the framework folder. All other folders are optional. Keep the requirements folder if you want to ensure that your web-server has all the requirements for Yii to work.

Create a new Yii application.

  1. Open a terminal window.
  2. Go into the framework directory
  3. Run this command:

    ./yiic webapp ../myProjectName
  4. The new Yii application will be created at “[the path to the folder where the framework folder is located]/[myProjectName]”.
    You can access it with the following URL: http://mydomain/myYiiPath/myProjectName/index.php

Copy YiiStrap.

  1. Download the latest YiiStrap extension from here: http://www.getyiistrap.com
  2. Create a new folder called “bootstrap” in your new Yii applications protected/extensions folder
  3. Unzip the YiiStrap zip into this new older

Change configuration.

  1. Open your new Yii applications protected/config/main.php file
  2. Add this to the beginning of the file:
    Yii::setPathOfAlias(‘bootstrap’, realpath(__DIR__ . ‘/../extensions/bootstrap’));
  3. Add these to your return array:
    // path aliases
    ‘aliases’ => array(
    ‘bootstrap’ => realpath(__DIR__ . ‘/../extensions/bootstrap’), // change this if necessary
    ),
    ‘import’=>array(
    ‘application.models.*’,
    ‘application.components.*’,
    ‘bootstrap.behaviors.TbWidget’,
    ‘bootstrap.helpers.*’,
    ‘bootstrap.widgets.*’,
    ‘bootstrap.helpers.TbHtml’,
    ),
    ‘modules’=>array(
    // uncomment the following to enable the Gii tool
    ‘gii’=>array(
    ‘class’=>’system.gii.GiiModule’,
    ‘password’=>’admin123′,
    // If removed, Gii defaults to localhost only. Edit carefully to taste.
    ‘ipFilters’=>array(‘127.0.0.1′,'::1′),
    ‘generatorPaths’ => array(‘bootstrap.gii’),
    ),
    ),

    ‘components’=>array(
    . . . . . . . . .
    . . . . . . . . .
    ‘bootstrap’ => array(
    ‘class’ => ‘bootstrap.components.TbApi’,
    ),

    ‘db’=>array(
    ‘connectionString’ => ‘mysql:host=localhost;dbname=pmtool’,
    ’emulatePrepare’ => true,
    ‘username’ => ‘jessie’,
    ‘password’ => ‘jessonita’,
    ‘charset’ => ‘utf8′,
    ),
    . . . . . . . . .
    . . . . . . . . .
    ),

Use Gii: Automated Code Generation.

Use the Gii Automated Code Generator to create CRUDs for your tables. The tools is pretty straight forward. Here is the URL:
http://myDomain/myYiiPath/index.php?r=gii/

That’s it! Open the model, controller and view folder in the protected folder to see how they are written.

Create your web application with Yii from command prompt

1. Download Yii from following url: http://www.yiiframework.com/download/

2. Copy yii folder to your c: drive

2. Click Start Menu->Run and type cmd and enter.

3.  In the command prompt type c:\yii\framework and enter

4. Open yii.bat file in a text editor, and add following line just below the ” set PHP_COMMAND=php.exe ”

cd C:\xampp\php\

5. From the command prompt, type following command and enter

C:\yii\framework>yiic webapp <path to your webapp folder inside htdocs>

C:\yii\framework>yiic webapp c:\xampp\htdocs\<your application folder>

It will ask for permission to create web application file in your application folder, type “yes” and enter.

6. Open browser and enter url like following:

http://localhost/<your web app folder>

That’s it!

Creating a CRUD using Yii Framework

Open /protected/config/main.php

uncomment the following to enable the Gii tool:

'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'rajeev',
// If removed, Gii defaults to localhost only. Edit carefully to taste.

'ipFilters'=>array('127.0.0.1','::1'),
),

uncomment the following to use MySql db:
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=db_sch_library',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),

Next you have to create a databse in mysql for your application and a table:

In my case it is db_sch_library, and table is books. The structure is given below:

CREATE TABLE books (
id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
title VARCHAR( 255 ) NOT NULL ,
description TEXT NOT NULL ,
isbn VARCHAR( 50 ) NOT NULL ,
price VARCHAR( 50 ) NOT NULL
) ENGINE = MYISAM ;

Then you have to call the gii using browser like following:

http://localhost/sch_library/index.php?r=gii

Then it will ask for gii password, enter password

Then you will get a code generator page with following options:

1. Controller Generator
2. Crud Generator
3. Form Generator
4. Model Generator
5. Module Generator

Click on the like Model Generator

In the model generator page, you have to enter Table Name. The Model class will come automatically in the Model Class

text box. Click on Preview button. Then it will show the code file and Generate Button. Click on Generate button.

Then click on link Crud Generator, and it will ask for the Model Class name and Controller ID. Enter the Model name which

you have created earlier.The controller id will come automalically. Click on Preview button to preview the code files and

after that Click on Generate Button.
Then there will be a link “try it now”to see the result or you can browse like this:
http://localhost/<web_app_dir>/index.php?r=books

That’s it

Create your web application with Yii framework

Download Yii framework (http://www.yiiframework.com), unpack it and copy it to the root folder(c:)

//htdocs folder(if your are using xampp) or your web folder.

Start->Run->cmd and cd to c:\yii\framework folder.

Next, you have to run yiic command to create your web application

The syntax for using yiic command is:

yiic webapp <path_to_webroot>/<your_web_app_directory>

In my case, it is:

c:\yii\framework>yiic webapp c:\xampp\htdocs\team_schogini

When you execute the above command, it will ask following question:

Create a Web application under ‘C:\xampp\htdocs\team_schogini’? [Yes|No]

Here you have to type Yes and press enter. Then it will create your web application directory and generate all the required files.

Now you can browse like following:

http://localhost/team_schogini/

 

Yii – A high performance PHP framework

Yii is a high performance component based Rapid Application Development PHP framework for developing large-scale Web application. The name Yii stands for easy, efficient and extensible. Yii is a pure Object Oriented Programming framework.

Requirements:- You need a PHP 5.1.0 supporting web server.

Areas of application:- Web portals, forums, e-commerce, content management system, etc.

Yii Installation:-  Download Yii framework from http://www.yiiframework.com/

Unzip and put the yii folder to the web accessible directory. If you are using xampp, you can put the yii folder inside htdocs.

After installing Yii, you can use following url to verify that your server satisfies all the requirements of Yii,

http://hostname/<path to yii folder>/requirements/index.php