Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Introduction to Codeigniter

2.766 visualizaciones

Publicado el

Small Talk @ C4Labs

Publicado en: Tecnología
  • Sé el primero en comentar

Introduction to Codeigniter

  1. 1. Introduction toCodeIgniter Zeroplex 2012/06/14
  2. 2. 初學 PHP  買書  線上文件 2
  3. 3. BUT 3
  4. 4. 書上不會提到 4
  5. 5. 重複的程式碼$user = trim( mysql_escape_string($_POST[„user‟] ));$pwd = trim( mysql_escape_string($_POST[„pwd‟] )); 5
  6. 6. 參考 PHPWind 程式碼,後重新修改自用程式架構 6
  7. 7. 架構$ tree ● ├── html ├── lib ├── upload ├── config.php.sample ├── global.php └── index.php 7
  8. 8. 混亂的程式碼 8
  9. 9. 混亂的程式碼 HTML 9
  10. 10. 混亂的程式碼 CSS 10
  11. 11. 混亂的程式碼 HTML 11
  12. 12. 混亂的程式碼 HTML 12
  13. 13. 混亂的程式碼 PHP 13
  14. 14. 混亂的程式碼 Smarty Template Engine 14
  15. 15. 問題仍然存在 相當耗時 不夠安全 不容易重複使用 佈署困難 15
  16. 16. PHP Frameworks  Modules  Templates  MVC  DB Objects  Validation 16
  17. 17. PHP Frameworks 17
  18. 18. PHP Frameworks 較知名的 framework  Zend  CakePHP  Symfony 18
  19. 19. Benchmarks ab –c 100 –n 30000 19
  20. 20. 拿不定主意 20
  21. 21. 直到PHPconf 2011 21
  22. 22. 22
  23. 23. 23
  24. 24. 24
  25. 25. So .... 25
  26. 26. CodeIgniter
  27. 27. CodeIgnter  麻雀雖小五藏俱全 27
  28. 28. CodeIgnter  麻雀雖小五藏俱全  沒有複雜的設定 28
  29. 29. CodeIgnter  麻雀雖小五藏俱全  沒有複雜的設定  效能佳 29
  30. 30. CodeIgnter  麻雀雖小五藏俱全  沒有複雜的設定  效能佳  中文文件 30
  31. 31. CodeIgnter  麻雀雖小五藏俱全  沒有複雜的設定  效能佳  中文文件 (其實只有一半是中文 XD) 31
  32. 32. CodeIgniter 簡介  Installation  Structure  Configuration  URLs  Controller / Model / View  Built-in Functions  Sparks 32
  33. 33. Installation 1. wget 2. unzip CodeIgniter-2.1.0.zip ..... Done ! 33
  34. 34. 34
  35. 35. 如果沒有成功 35
  36. 36. 不要讓日落靠近 36
  37. 37. Structure ─── application ├── config ├── controllers ├── models ├── views ├── ........ ├── system └── index.php 37
  38. 38. Structure ─── application 網站程式所在位置 ├── config ├── controllers ├── models ├── views ├── ........ ├── system └── index.php 38
  39. 39. Structure ─── application ├── config ├── controllers ├── models ├── views ├── ........ ├── system CodeIgniter 核心 └── index.php 39
  40. 40. Configuration  application/config  config.php  database.php  autoload.php 40
  41. 41. Configuration  application/config  config.php ─── site URL  database.php charset log/cache path  autoload.php session / cookie 41
  42. 42. Configuration  application/config  config.php  database.php  autoload.php 42
  43. 43. Configuration  application/config  config.php  database.php  autoload.php ─── 在程式執行時自動 載入模組或函式 43
  44. 44. URLs  URL segment map to Controller index.php/post/show/2385 44
  45. 45. URLs  URL segment map to Controller index.php/post/show/2385 Controller Argument Method 45
  46. 46. URLs class Post extends CI_Controller { public function show($id){ // Get post information } } 46
  47. 47. Controller application/controller/welcome.php: class Welcome extends CI_Controller { public function index(){ $this->load-> view(welcome_message); } 47
  48. 48. Controller application/controller/welcome.php: class Welcome extends CI_Controller { public function index(){ $this->load-> view(welcome_message); } 48
  49. 49. Controller application/controller/welcome.php: class Welcome extends CI_Controller { public function index(){ $this->load-> view(welcome_message); } 49
  50. 50. Your Own Controller controller/hello.php class Hello extends CI_Controller { public function greeting($id){ echo “Hello $id”; } } 50
  51. 51. Your Own Controller controller/hello.php class Hello extends CI_Controller { public function greeting($id){ echo “Hello $id”; } } Print „Hello C4Labs‟ : index.php/hello/greeting/C4Labs 51
  52. 52. Your Own Controller Deny method from URL access class Hello extends CI_Controller { public function _greeting($id){ echo “Hello $id”; } } Underline 52
  53. 53. View  位於 application/view/  由 controller 載入  Template parser 53
  54. 54. View  application/view/hello.php <html><body> <h1> Hello <?php echo $id;?> </h1> </html></body> 54
  55. 55. View  Load view function hello($id){ $data[„id‟] = $id; $this->load->view(„hello‟, $data); } 55
  56. 56. Template Parser <html><body> <h1> Hello <?php echo $id;?> </h1> </html></body> PHP 56
  57. 57. Template Parser <html><body> <h1> Hello {id} </h1> </html></body> 57
  58. 58. Template Parser function hello($id){ $this->load->library(„parser‟); $data[„id‟] = $id; $this->parser-> parse(„hello, $data); } 58
  59. 59. Model  Process data in database class User extends CI_Model{ function getUser($uid) { ... } function deleteUser($uid) { ... } } 59
  60. 60. Model  Load model in controller $this->load->model(„user‟); $user = $this->user->getUser(2); 60
  61. 61. Built-in Functions  Library  Input  Template Parser  File Uploading  Helper  URL  CAPTCHA 61
  62. 62. Built-in Functions  Load  $this->load->library(„upload‟);  $this->load->helper(„url‟);  Use  $this->upload->data();  echo site_url(); 62
  63. 63. No enough? 63
  64. 64. Sparks ! 64
  65. 65. Sparks  Package management system for CodeIgniter  Easy to install  Lots of useful packages  Makes you lazy 65
  66. 66. Install Sparksphp -r "$(curl -fsSL http://getsparks.org/go-sparks)" 66
  67. 67. Using Sparks $ php tools/spark search redis menu - The Menu library is used to .... redis - A CodeIgniter library to .... $ php tools/spark install redis Retrieving spark detail from getsparks.org ........ Spark installed to ./sparks/redis/0.3.0 - Youre on fire! 67
  68. 68. Using Packages  Load and call $this->load->spark(„redis/0.3.0‟); $this->redis->set(„foo‟, „bar‟); 68
  69. 69. More  CodeIgniter 中文討論區 http://www.codeigniter.org.tw/forum/  CodeIgniter Wiki http://codeigniter.com/wiki 69
  70. 70. Q & A 70
  71. 71. Live Debug Demo 71
  72. 72. Thank You 72

×