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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
openwebschool
August 22, 2012
Programming
370
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
260
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
270
Other Decks in Programming
See All in Programming
Security issues being discussed on Web Platforms
petamoriken
0
960
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.5k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
160
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
280
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.8k
What We Talk About When We Talk About XP
m_seki
2
640
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
720
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
340
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
2.3k
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.5k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Done Done
chrislema
186
16k
Navigating Team Friction
lara
192
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
240
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Un-Boring Meetings
codingconduct
0
420
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
450
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/