Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
11 - CodeIgniter - OpenWebSchool
Search
openwebschool
August 22, 2012
Programming
380
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
11 - CodeIgniter - OpenWebSchool
openwebschool
August 22, 2012
More Decks by openwebschool
See All by openwebschool
09 - Node.JS - OpenWebSchool
openwebschool
1
400
07 - Javascript - OpenWebSchool
openwebschool
3
350
08 - js frontend & jQuery - OpenWebSchool
openwebschool
3
290
05 - MySQL - OpenWebSchool
openwebschool
1
270
06 - PHP & MySQL - OpenWebSchool
openwebschool
1
300
03 - PHP II - OpenWebSchool
openwebschool
2
400
04 - CSS - OpenWebSchool
openwebschool
4
360
01 - W3 intro - OpenWebSchool
openwebschool
3
260
02 - PHP I - OpenWebSchool
openwebschool
3
280
Other Decks in Programming
See All in Programming
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.3k
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
360
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
460
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
370
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
970
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
1
280
Simple Storage Service(S3) is not simple
iwatsukayura
0
270
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.8k
ジョジョの世界をXRで再現する
mofurune
0
150
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
560
Everyday Curiosity
cassininazir
0
350
Docker and Python
trallard
47
4.2k
Optimizing for Happiness
mojombo
378
71k
For a Future-Friendly Web
brad_frost
184
10k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Building Applications with DynamoDB
mza
96
7.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Code Reviewing Like a Champion
maltzj
529
40k
Side Projects
sachag
456
43k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Transcript
Ensky / 林宏昱
What's Framework Framework ,中文是「框架」 顧名思義就是一個框框,你寫的東西都要在那個框 框裡。
What's Framework 更精確的定義,就是有人寫了一些 code , 那些 code 提供了一個規範, 規定你怎麼寫網站、檔案應該存在哪裡, 透過那些規定,你可能可以更快寫出一個架構不錯
的網站。
你可能會覺得, PHP 那麼簡單,我也寫很快阿, 為什麼還需要 Framework 來「規範」我呢? 我崇尚自由!
Why Framework? 但是阿,有句諺語說, 「 code 過了三個月就不是你寫的了」 自己寫的 code 要是沒有 document
, 很快就忘了你之前的邏輯
或者是,你在團隊中工作, 而他們全部都需要了解你的 Coding style 。 身為工程師的你超懶得寫 document 的阿
Why Framework? • 你需要大量 Document 讓你的工作伙伴快速上手 • 你需要一套規範讓大家 coding 邏輯相同
而這些是一個好的 Framework 會提供給你的!
Framework to NewHand 基本上不建議新手學 Framework 。 新手對於 PHP 的各種特性還不夠熟悉, 很容易被
Framework 帶來的各種「糖衣」誘惑 一旦使用之後從此對於架構的概念就定型了 從此在也無法接受其他架構 (即使別的 FrameWork 可能設計的更好)
Framework to NewHand Framework 也是人寫出來的, 在使用的時候你一定要知道每個功能背後是 怎麼寫的,甚至你可以自己 trace code 。
如此一來,才不會被 Framework 綁住, 輕則不能輕易換 Framework , 重則沒有 Framework 就不會寫 code 了。
Framework to NewHand 因此我對新手的建議是 多練、多嘗試 趁自己的架構還沒有被定型, 多嘗試研發自己的架構, 寫的順了,想快速開發,再 survey 一套順手的
Framework 而不是一開始就直接碰他。
Popular PHP Framework http://www.phpframeworks.com/index.php
CodeIgniter is an PHP Framework • 小巧 • 輕量 •
說明文件多、完整 • 速度快 • 簡單 我講 CI 不代表 CI 就是最好的 Framework , 每個人喜歡的 Framework 不同。
Model View Controller MVC 是一個程式設計的概念, 和 OOP 很像, 並不是網頁設計獨有的東西。 但在網頁設計上剛好很適合採用
M-V-C 架構, 因此幾乎大家的 PHP Framework 都採此架構設計。
Model View Controller Model View Controller
Model View Controller • Controller – 邏輯判斷 Ex: 這頁做些什麼事情?(登入、註冊、表單) 我需要哪些資料?
中間人的角色 • Model – 可以重複利用的函數群 可以被不同的 Controller load 比如說 Database 的操作很適合成為 Model
Model View Controller • View – Layout 各種不同的網頁內容 此種頁面純粹印出 Controller
提供的變數 ( or 陣列) 不做任何邏輯判斷。
Model View Controller Model View Controller Browser 1.GET /login 2.Load
Auth model 3.Return Auth model 4.Load Login page 5. Return Login Page 6. Return Page
Router CI 的檔案管理是用 URL PATH 管理的, 當一個網址長這樣: http://www.codeigniter.org.tw/downloads 他其實代表的意思是: http://www.codeigniter.org.tw/index.php/downloads
而利用 Web Server 的 URL Rewrite 功能, 達到重新導向的目的。 因此,所有網址都經由 index.php 做統一集中的 route 動作
Router index.php 看到一個 url 長這樣 http://ensky.tw/auth/login 根據 CI 的 router
,他會去找 controller/auth.php 這隻程式,然後去執行他的 login function Demo Code
Router 而如果再繼續 / 下去,則會被當成該 method 的 params 傳進去。 也因為 CI
的 Router 機制, 我們看到一個 url 就知道去哪裡找他, 檔案在哪裡都一清二楚不會找不到。 http://xxxx/controller/method/params
Loader 為了加快速度, CI 的所有元件都是 load by need 的, 需要的時候在使用 loader
把它 load 進來。 load 進來之後就會綁到 $this 上面, 比如說: $this->load->model('curl'); $this->curl->xxx(); 就不需要用傳統的 require_once __dir__ ."/curl.php"; $curl = new curl();
Demo Time I'll show you controller, model, view
Library 有些時候你會想用別人寫的 Library , 但他不是用 CI 這套 Framework ,怎麼辦? 沒關係,
CI 可以讓你使用別人寫的 Library , 用法一樣輕鬆寫意。 $this->load->library('phpmailer'); $this->phpmailer->send('
[email protected]
');
CI Session CI 製作團隊似乎覺得 php native 的 session 不是很好用,所以自己設計了一套 session
, 完全使用 cookie 加密存放資料, 也可以選擇使用 db 存放。 $this->session->set_userdata('id', 'ensky'); echo $this->session->userdata('id'); // ensky
CI Session Note: 如果有個 session 沒有被設定過 (!isset) 的話 不會噴錯誤,他會是 False
有個 flash_data 機制頗好用, 若某個 session 只想保留給下一頁使用, 就可以用 flashdata 來存 $this->session ->set_flashdata('errmsg', 'error!'); <?=$this->session->flashdata('errmsg')?>
Database • 基本上就完全是我前幾天講的 Active Record $result = $this->db->select('*') ->from('user') ->where('id',
'ensky') ->get()->result_array(); $insert_data = ['id'=>'ensky', 'gender'=>'boy']; $this->db->insert('user', $insert_data);
Other feature • Form Validation – 可以讓你很快的做表單輸入格式驗證 比如說密碼長度大於 blablabla 或者是這欄只能是數字,諸如此類。
http://www.codeigniter.org.tw/user_guide/libraries /form_validation.html
Other feature • input class – 使用者的資料向來都要視為很不安全, 比方說 get, post,
cookie 等資訊, ci 就把所有使用者的 input 包成一個 class , 可以用類似方式取用 $id = $this->input->post('id'); $cookie_id = $this->input->cookie('id');
DEMO!
Reference • 絕對強大的中文手冊 http://www.codeigniter.org.tw/user_guide/