You are on page 1of 7

TUTORIALS Ci t WebApp ban u bng Yii FrameWork 1.

Kim tra cu hnh host c chy c Yii hay khng - Ti b Yii v (trang ch nh) - Gii nn vo th mc Webroot ( y mnh dng Xampp trn my c ng dn l C:/xampp v gii nn vo C:/xampp/htdocs/Yii) - Vo trnh duyt truy cp ti: WebRoot/folder-Yii/requirements/ Vi 5 dng u pass nh hnh l ta c th dng c Yii FrameWork

- Sau khi t yu cu chuyn sang cu hnh chy Yii Command

2. Cu hnh PHP chy command - Mi ngi c th to Path cho PHP truy xut cho d

Thm ;folder-php\ vi folder-php l ng dn ti th mc PHP (v d C:/xampp/php) vo sau cng - Hoc c th vo config ngay ti framework cng c M file folder-Yii/framework/yiic.bat v sa nh sau PHP_COMMAND=php.exe thnh PHP_COMMAND=folder-php\php.exe Vi folder-php l ng dn ti th mc PHP (v d C:/xampp/php)

3. Command to WebApp M Commands ln v g folder-Yii/framework/yiic webapp webroot/project-name V d:


"C:/xampp/htdocs/yii/framework/yiic" webapp C:/xampp/htdocs/demoyii"

Y Enter tin hnh ci t. Truy cp : WebRoot/project-name xem project va to ra 4. Chy th WebApp - Sau khi truy cp chng ta s c mt trang web chy bng Yii FrameWork to sn v c chc nng login, logout, contact vi user c cp l admin/admin v demo/demo - ng nhp, ng xut - Contact vi admin bng chc nng Contact + Localhost phi cu hnh li mi s dng c chc nng gi mail + Vo file: Webroot/project-name/protected/config/main.php tm 'adminEmail'=>'webmaster@example.com' 'adminEmail'=>'webmaster@example.com' v thay email admin vo - Vo th mc cha project to s c cu trc nh sau: + index.php: cha thng tin v path ca file config v th mc framework + assets: cha cc AJAX v JQUERY + css: cha cc file CSS + protected: phn chnh ca project vi cu trc theo m hnh MVC Controllers: cha cc file Controller Models: cha cc class truy xut CSDL Views: cha cc file hin th ca project Ngoi ra cn c cc mc khc: Config: cu hnh ca project (Name, CSDL, Email, ) Tests: cha file dng phpunit test ton b project Components, extensions, v.v

5. Cu hnh Database v ci t Gii (CRUD) - Truy xut Webroot/project-name/protected/config v chnh sa cc thng tin file main.php c th truy cp CSDL v to Gii Tools qun l CSDL, sinh code qun l bng giao din web - Kt ni CSDL: tm n
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db' L kiu CSDL SQLite, chng ta c th sa thnh cc kiu CSDL sau + MySQL: 'connectionString' => 'mysql:host=localhost;dbname=database_name', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', + PostgreSQL: 'connectionString' => 'pgsql:host=localhost;port=5432;dbname= database_name' + SQL Server: 'connectionString' => 'mssql:host=localhost;dbname= database_name' + Oracle: 'connectionString' => 'oci:dbname=//localhost:1521/ database_name' kt ni vi CSDL ta dng code Yii::app()->db bt c ni no. Ci t Gii: tm on

'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'Enter Your Password Here', 'ipFilters'=>array('127.0.0.1','::1'), b comment i, t password truy cp vo Gii, save li v truy cp theo ng dn: Webroot/project-name/index.php?r=gii nhp password to

6. S dng Gii Tools (CRUD) - To Models kt ni ti CSDL Sau khi cu hnh kt ni CSDL ta cn c mt Model truy xut v thao tc vi CSDL, Gii Tools cung cp cho ta bng cng c Model Generator, ta cn in tn Table lm vic v tn Model nn trng tn hoc gn ging tn Table d nh khi s dng v chnh sa -> n Preview nu ng thng tin s c mt Model mi c gi lp, nhp vo xem code v n Generate to Model trong th mc models

To Controller iu khin Chng ta cn to mt Controller iu khin vic truy xut, x l v hin th thng tin t CSDL vi cng c Controller Generator, in tn Controller (trng vi tn Model nu code n gin cho d qun l) v thc hin nh trn

To CRUD (Creat, Read, Update, Delete) Cui cng hin th v x l vi CSDL ta dng cng c Crud Generator, ta in Model v Controller va to vo v thc hin tng t

7. Chy code sau khi dng Gii Tools (CRUD) - Sau khi dung Gii Tool to cc Model, Controller v View ta s truy xut bng ng dn Webroor/project-name/index.php?r=controller-name V d: http://localhost/yii/newweb/index.php?r=books - n y hy xem thnh qu mnh lm c v t tm hiu cc cng c c to sn bi Yii v Gii nh !

You might also like