Successfully reported this slideshow.
Your SlideShare is downloading. ×

Benefit of CodeIgniter php framework

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
MVC in PHP
MVC in PHP
Loading in …3
×

Check these out next

1 of 37 Ad

More Related Content

Advertisement

Similar to Benefit of CodeIgniter php framework (20)

More from Bo-Yi Wu (20)

Advertisement

Recently uploaded (20)

Benefit of CodeIgniter php framework

  1. 1. Benefit of CodeIgniter PHP Framework Appleboy (Bo-Yi Wu) 2010.09.19
  2. 2. <ul><li>吳柏毅 (Bo-Yi Wu) – Software Engineer </li></ul><ul><li>Gemtek  - Wireless Broadband Anywhere ( 正文科技 ) </li></ul><ul><li>Android Linux Kernel Driver, Switch Router embedded Linux </li></ul><ul><li>CodeIgniter 繁體中文手冊翻譯 </li></ul><ul><li>CodeIgniter 繁體中文網站及討論區 </li></ul><ul><li>PHP Plurk API (Google Code) </li></ul>About Me
  3. 3. Evolution of Web Development index.php about.php news.php links.php contact.php product.php 剛開始設計網站的時候……… ..
  4. 4. Evolution of Web Development index.php page.php header.php news.php footer.php 當你知道每個網頁都有共同的 header 跟 footer 部份
  5. 5. Evolution of Web Development index.php Controller Model View 當你使用 PHP Framework 設計網站時……
  6. 6. Why use Framework ?
  7. 7. Why use Framework ? <ul><li>A web application framework </li></ul><ul><ul><li>Dynamic websites </li></ul></ul><ul><ul><li>Libraries for database access </li></ul></ul><ul><ul><li>Template frameworks </li></ul></ul><ul><ul><li>Session management </li></ul></ul><ul><ul><li>Pagination function </li></ul></ul><ul><ul><li>Often promote code reuse </li></ul></ul>Many more …….
  8. 8. MVC Architecture WEB SERVER ROUTES Controller View MODEL LAYOUT Database Client BROWSER
  9. 9. MVC <ul><li>View (views/showProduct.php) </li></ul><ul><li><html> </li></ul><ul><li><body> </li></ul><ul><li><p>Product Count:<?=$count?></p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>Controller (controllers/product.php) function showProduct($id) { $this->load->model(“product”); $count = $this->product->getCount($id); $data[‘count’] = $count; $this->load->view(“showProduct”, $data); } Model (controllers/product.php) function getCount($id) { $this->db->where(“id”, $id); $this->db->from(“my_product”); $query = $this->db->get(); return $->num_rows(); } View Controller Model
  10. 10. Public Web Framework
  11. 11. Why Choose CodeIgniter <ul><li>Small ( 非常小 ) </li></ul><ul><li>Fast ( 非常快速,想用什麼就 load 什麼 ) </li></ul><ul><li>Simple ( 非常簡易 ) </li></ul><ul><li>Customer </li></ul><ul><ul><li>管理者可於幾分鐘內安裝好 CI Framework </li></ul></ul><ul><ul><li>對於初學者有豐富線上中文文件 </li></ul></ul><ul><li>Cleaner Code ( 方便學習如何寫 Framework) </li></ul>
  12. 12. What is CodeIgniter???? <ul><li>An Open Source Web Application Framework </li></ul><ul><li>Nearly Zero Configuration </li></ul><ul><li>MVC (Model View Controller) Architecture </li></ul><ul><li>DB Object </li></ul><ul><li>Templating </li></ul><ul><li>Caching </li></ul><ul><li>Modules </li></ul><ul><li>Helper </li></ul><ul><li>Validation </li></ul>
  13. 13. How to install CodeIgniter ?
  14. 14. <ul><li>Requirtment </li></ul><ul><ul><li>Windows, FreeBSD, Linux...... </li></ul></ul><ul><ul><ul><li>Apache, lighttpd, Nginx </li></ul></ul></ul><ul><ul><li>PHP </li></ul></ul><ul><ul><ul><li>PHP 4.3.2 or Higher.... </li></ul></ul></ul><ul><ul><li>Database </li></ul></ul><ul><ul><ul><li>MySQL, MySQLi, MS SQL, Postgres, SQLite... </li></ul></ul></ul>
  15. 15. <ul><li>wget http://codeigniter.com/ ....... </li></ul><ul><li>unzip CodeIgniter_1.7.2.zip </li></ul><ul><li>edit </li></ul><ul><li>application/config/config.php </li></ul><ul><li>application/config/database.php </li></ul>You can see http://localhost/ci/index.php
  16. 16. Application Flow Of CodeIgniter
  17. 17. CodeIgniter URL <ul><li>http://localhost/ news.php ? mode=edit & id=10 </li></ul>http://localhost/index.php/ news / edit / 10
  18. 18. CodeIgniter Directory <ul><li>system </li></ul><ul><li>user_guide (English Document) </li></ul><ul><li>index.php </li></ul>設定網站 Application 目錄 , 及 CodeIgniter 核心目錄
  19. 19. CodeIgniter System Directory <ul><li>Application </li></ul><ul><li>Cache </li></ul><ul><li>Codeigniter </li></ul><ul><li>Database </li></ul><ul><li>.............. </li></ul>Conroller, Model, Views
  20. 20. CodeIgniter Application Directory <ul><li>Config -> 系統相關設定檔 </li></ul><ul><li>Controllers -> 放置個人 Controller </li></ul><ul><li>Errors -> CI error message </li></ul><ul><li>Helpers -> CI Helpers </li></ul><ul><li>Hooks </li></ul><ul><li>Language -> 多國語系 </li></ul><ul><li>Libraries -> 個人常用函式 </li></ul><ul><li>Models -> Database 相關語法 </li></ul><ul><li>Views -> 畫面 </li></ul>
  21. 21. Controller <ul><li>class News extends Controller { </li></ul><ul><li>function __construct() { </li></ul><ul><li>parent::Controller(); </li></ul><ul><li>} </li></ul><ul><li>function index (){ </li></ul><ul><li>echo “welcome CodeIgniter”; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Should be placed under “application/controllers”
  22. 22. Controller <ul><li>class News extends Controller { </li></ul><ul><li>function __construct() { </li></ul><ul><li>parent::Controller(); </li></ul><ul><li>} </li></ul><ul><li>function index (){ </li></ul><ul><li>} </li></ul><ul><li>function edit ( $id ){ </li></ul><ul><li>echo “news id is ” . $id; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>url: http://localhost/ news / edit / 10
  23. 23. Views Should be placed under “application/views/index.php” <html> <title> My First CodeIgniter Project</title> <body> <h1>Welcome to My CodeIgniter</h1> </body> </html>
  24. 24. Views Calling a VIEW from Controller $this->load->view(‘index’); Data Passing to a VIEW from Controller function index() { $data = array( ‘ full_name’ => ‘appleboy’, ‘ email’ => ‘appleboy.tw@gmail.com’ ); $this->load->view(‘index’, $data); }
  25. 25. Views <html> <title> ..::Personal Info::.. </title> <body> Full Name : <?=$full_name;?> <br /> E-mail : <?=$email;?> <br /> </body> </html>
  26. 26. Models Models Should be placed Under “application/models/” class News_model extends Model { function Mlb_model() { parent::Model(); } function get_news ($id) { $this->db->select(‘news_id, news_name'); $this->db->from('project_news'); $query = $this->db->get(); return $query->result_array(); } }
  27. 27. Loading a Model inside a Controller <ul><li>$this->load->model(‘news_model’); </li></ul><ul><li>$data = $this-> news_model -> get_news (); </li></ul>
  28. 28. CodeIgniter Libraries <ul><li>Database ( 支援多種資料庫型態 ) </li></ul><ul><li>File Uploading ( 檔案上傳 ) </li></ul><ul><li>Pagination ( 分頁 ) </li></ul><ul><li>Input and Security (SQL Injection) </li></ul><ul><li>Session </li></ul><ul><li>Form Valitation ( 表單驗證 ) </li></ul>
  29. 29. How to load Libraries?
  30. 30. <ul><li>$this->load->library(‘ class name’ ); </li></ul><ul><li>$this->load->library(‘ validation’ ); </li></ul>
  31. 31. CodeIgniter Helpers <ul><li>Url helper </li></ul><ul><ul><li>site_url() </li></ul></ul><ul><ul><li>base_url() </li></ul></ul><ul><ul><li>anchor() </li></ul></ul><ul><ul><li>mailto() </li></ul></ul><ul><ul><li>auto_link() </li></ul></ul><ul><li>Download helper </li></ul><ul><ul><li>force_download() </li></ul></ul>
  32. 32. How to load helper?
  33. 33. <ul><li>$this->load->helper(‘helper name’); </li></ul><ul><li>$this->load->helper(‘download’); </li></ul>
  34. 34. Auto-loading Resources <ul><li>Core classes found in the &quot; libraries &quot; folder </li></ul><ul><li>Helper files found in the &quot; helpers &quot; folder </li></ul><ul><li>Plugins found in the &quot; plugins &quot; folder </li></ul><ul><li>Config files found in the &quot; config &quot; folder </li></ul><ul><li>Language files found in the &quot; language &quot; folder </li></ul><ul><li>Models found in the &quot; models &quot; folder </li></ul>
  35. 35. application/config/autoload.php <ul><li>$autoload [' libraries '] = array(); </li></ul><ul><li>$autoload [' helper '] = array(); </li></ul><ul><li>$autoload [' plugin '] = array(); </li></ul>
  36. 36. CodeIgniter Online Resource <ul><li>CodeIgniter Wiki ( 超多經典範例及外掛 ) </li></ul><ul><li>繁體中文線上文件 ( http://goo.gl/RwaC ) </li></ul><ul><li>繁體中文討論區 ( http://goo.gl/CfJi ) </li></ul><ul><li>Google CodeIgniter ........ </li></ul>
  37. 37. <ul><li>Thank You </li></ul>

×