Sunday, November 18, 2012

Howto Yii 1, a PHP framework

This framework seemed worth while to test out. Steps to get started is as follows;

Step 1: Install the framework.
From the www.yiiframework.com site, follow the instructions for pre-requisite to install the Yii framework. Typically you will need

  1. Apache web browser
  2. PHP 5.1 and newer
  3. PHP PDO
  4. A database


Download Yii-1.1...tar.gz (in tar.gz format) from http://www.yiiframework.com/download/
Extract the tar.gz file to the web folder /var/www/html/yii1

It is also a good point to download the Yii-docs-1.1...tar.gz and extract it to follow its references and tutorials in PDF.

Step 2: Create the skeleton of a new web app.
At the prompt, access the framework's directory /var/www/html/yii1/framework

Type the following:
./yiic webapp ../testdrive

or in windows
yiic webapp ..\testdrive

Open a web browser and access the testdrive application
http://localhost/yii1/testdrive

Step 3: Configure the timezone for the web app.
If an error on the timezone appears, complete following steps

vi /var/www/html/yii1/testdrive/protected/config/main.php

Just before the last line, add the timezone.


'timeZone'=>'Asia/Kuala_Lumpur',
);

Access the testdrive application with the web browser, the error on timezone is gone. It does inform users the following;


You may change the content of this page by modifying the following two files:

View file: C:\Program Files\www\yii1\testdrive\protected\views\site\index.php
Layout file: C:\Program Files\www\yii1\testdrive\protected\views\layouts\main.php



Step 4. Understanding the structure
It is good to know the directories built for the testdrive web application under /var/www/html/yii1/testdrive. From here on, I will refer to the directory /var/www/html/yii1/testdrive as

/index.php
/index-test.php
/assets/  <=Empty
/css/  <=Contains 5 basic CSS files and a bg.gif file
/images/  <=Empty
/protected/  <=This is where your coding goes
/themes/  <=Several directories that is empty

Step 5. The database, mysql
Create a database named yii_testdrive, and load in the SQL from
/protected/data/schema.mysql.sql

By default it has the SQLLITE as its database, edit the file /config/main.php and comment out the following lines


'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),

Uncomment the mysql lines below it and edit the database connection


'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=yii_testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),



Step 6. Generating the pages based on the database

Uncomment the GII web-based code generator and change the default password to MyPassword


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



Open a web browser and point to the gii resource
 http://localhost/yii1/testdrive/index.php?r=gii

A login page appears, type the password as
MyPassword

You are then presented with the following to auto generate codes based on your database.


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



Thats all for now...will continue when time permits.

2 comments:

Unknown said...

Thanks for sharing information about yii framework. if you want to know more about it please view this
Yii framework Features and benefits

Unknown said...

Very nice blog… I always enjoy to read your blog tech post… Very good writing skill.. I appreciated what you have done here… Good job! Keep posting.

If you like to learn about Yii 2.0 beta version, please visit this video: www.youtube.com/watch?v=WwT6ar8nQGk

Blog Archive