Yii Basic talk
 Aaron Huang - 黃冠中
About Aaron
•   a.k.a aar0ntw

•   Nexdoor Web Developer

•   Development , System Design , Training ...etc

•   PHP , JavaScript , Ruby , Python ...etc

•   github, twitter : @aar0ntw

•   plurk : @smoraa

•   Blog: http://blog.buginception.com
Agenda
• Yii php framework tutorial
 •   Intro

 •   MVC pattern

 •   Http request life cycle in yii

 •   Folder Structure

 •   Tools

• live demo
• Q &A
Slide


• http://www.slideshare.net/guanzhonghuang/
  presentations
官方資源



•   http://www.yiiframework.com

•   http://www.yiiframework.com/doc/api/1.1/

•   http://www.yiiframework.com/doc/guide/1.1/en/
簡介
Yii 是什麼
Yii 是什麼

• 是一個 PHP 的 web framework
Yii 是什麼

• 是一個 PHP 的 web framework
• 是一個 MVC 架構的 php framework
Yii 是什麼

• 是一個 PHP 的 web framework
• 是一個 MVC 架構的 php framework
• 是一個快速開發的 php framework
Yii 是什麼

• 是一個 PHP 的 web framework
• 是一個 MVC 架構的 php framework
• 是一個快速開發的 php framework
• 是一個高效率的 php framework
為什麼要用 framework
為什麼要用 framework
•   因為 PHP 很劣
為什麼要用 framework
•   因為 PHP 很劣

•   寫起來很醜
為什麼要用 framework
•   因為 PHP 很劣

•   寫起來很醜

•   看起來很散
為什麼要用 framework
•   因為 PHP 很劣

•   寫起來很醜

•   看起來很散

•    起來很怪
為什麼要用 framework
•   因為 PHP 很劣

•   寫起來很醜

•   看起來很散

•    起來很怪

•   因為很多人都說會寫 PHP
為什麼要用 framework
•   因為 PHP 很劣

•   寫起來很醜

•   看起來很散

•    起來很怪

•   因為很多人都說會寫 PHP

•   但實際上不太會寫。
那為什麼還要用 PHP
那為什麼還要用 PHP

• 門檻低
那為什麼還要用 PHP

• 門檻低
• 好上手
那為什麼還要用 PHP

• 門檻低
• 好上手
• 誰都會寫
那為什麼還要用 PHP

• 門檻低
• 好上手
• 誰都會寫
• 資源豐富
劣 即是 夯
需求
需求
• 介面的規範
需求
• 介面的規範
• 格式的標準
需求
• 介面的規範
• 格式的標準
• 程式碼的風格
需求
• 介面的規範
• 格式的標準
• 程式碼的風格
• 資料夾的結構
需求
• 介面的規範
• 格式的標準
• 程式碼的風格
• 資料夾的結構
• 開發者的紀律
常見 PHP 程式流程
index.php    about.php    page.php




access.php                 list.php




delete.php   update.php   create.php
Yii 程式流程
                                app
index.php      application
                             component




               controller




                 widget



 model                         view
差異
差異
• 介面化
差異
• 介面化
• 易於維護
差異
• 介面化
• 易於維護
• 程式耦合性低
差異
• 介面化
• 易於維護
• 程式耦合性低
• 結構清楚
差異
• 介面化
• 易於維護
• 程式耦合性低
• 結構清楚
• 容易預期
MVC 模式
MVC 模式


• Model - View - Controller
MVC 模式


• Model - View - Controller
• 資料 - 畫面 - 中介控制
MVC 模式


• Model - View - Controller
• 資料 - 畫面 - 中介控制
• 商業邏輯 - 前端畫面 - 流程控管
Yii request 生命週期
index.php (Bootstrap)
                               app
  index.php   application
                            component




              controller




                widget



   model                      view
Yii::CWebApplication
                               app
  index.php   application
                            component




              controller




                widget



   model                      view
Yii::CComponent
                             app
index.php   application
                          component




            controller




              widget



 model                      view
Yii::CUrlManager
                                          app
index.php   application
                                       component

                          UrlManager



            controller




              widget



 model                                   view
Yii::CController
                             app
index.php   application
                          component




            controller




              widget



 model                      view
Yii::CActiveRecord
                              app
 index.php   application
                           component




             controller




               widget



  model                      view
CController::render
                               app
  index.php   application
                            component




              controller




                widget



   model                      view
Yii::CWidget
                             app
index.php   application
                          component




            controller




              widget



 model                      view
實際開發
資料夾結構
輔助工具
輔助工具



• yiic : command line tool
輔助工具



• yiic : command line tool
• Gii : Web UI tool
輔助工具 : CLI tool
輔助工具 : CLI tool

• yiic shell
輔助工具 : CLI tool

• yiic shell
 • model
輔助工具 : CLI tool

• yiic shell
 • model
 • controller
輔助工具 : CLI tool

• yiic shell
 • model
 • controller
 • crud
輔助工具 : CLI tool

• yiic shell
 • model
 • controller
 • crud
• yiic migrate
Live Demo
Q &A


你問,我盡量答
謝謝大家

Yiitalk