SlideShare a Scribd company logo
1 of 72
Introduction to

CodeIgniter


                    Zeroplex

                  2012/06/14
初學 PHP

    買書
    線上文件




            2
BUT



      3
書上不會提到



         4
重複的程式碼
$user = trim(
     mysql_escape_string($_POST[„user‟] )
);


$pwd = trim(
     mysql_escape_string($_POST[„pwd‟] )
);


                                           5
參考 PHPWind 程式碼,後重新修改自用程式架構

                             6
架構
$ tree
   ●


   ├── html
   ├── lib
   ├── upload
   ├── config.php.sample
   ├── global.php
   └── index.php

                           7
混亂的程式碼




         8
混亂的程式碼
     HTML




            9
混亂的程式碼


     CSS




           10
混亂的程式碼




     HTML




            11
混亂的程式碼


         HTML




           12
混亂的程式碼




         PHP




          13
混亂的程式碼

   Smarty Template Engine




                             14
問題仍然存在

   相當耗時
   不夠安全
   不容易重複使用
   佈署困難




              15
PHP Frameworks

    Modules
    Templates
    MVC
    DB Objects
    Validation




                  16
PHP Frameworks




                 17
PHP Frameworks

 較知名的 framework
     Zend
     CakePHP
     Symfony




                  18
Benchmarks

 ab –c 100 –n 30000




                      19
拿不定主意



        20
直到
PHPconf 2011


               21
22
23
24
So ....



          25
CodeIgniter
CodeIgnter

    麻雀雖小五藏俱全




                27
CodeIgnter

    麻雀雖小五藏俱全
    沒有複雜的設定




                28
CodeIgnter

    麻雀雖小五藏俱全
    沒有複雜的設定
    效能佳




                29
CodeIgnter

    麻雀雖小五藏俱全
    沒有複雜的設定
    效能佳
    中文文件




                30
CodeIgnter

    麻雀雖小五藏俱全
    沒有複雜的設定
    效能佳
    中文文件   (其實只有一半是中文 XD)




                             31
CodeIgniter 簡介

    Installation
    Structure
    Configuration
    URLs
    Controller / Model / View
    Built-in Functions
    Sparks

                                 32
Installation

 1. wget
 2. unzip CodeIgniter-2.1.0.zip


                           .....
   Done !



                                   33
34
如果沒有成功



         35
不要讓日落靠近



          36
Structure
   ─── application
       ├── config
       ├── controllers
       ├── models
       ├── views
       ├── ........
   ├── system
   └── index.php
                         37
Structure
   ─── application    網站程式所在位置
       ├── config
       ├── controllers
       ├── models
       ├── views
       ├── ........
   ├── system
   └── index.php
                                 38
Structure
   ─── application
       ├── config
       ├── controllers
       ├── models
       ├── views
       ├── ........
   ├── system         CodeIgniter 核心
   └── index.php
                                       39
Configuration

    application/config
        config.php
        database.php
        autoload.php




                          40
Configuration

    application/config
        config.php     ───   site URL
        database.php         charset
                              log/cache path
        autoload.php         session / cookie




                                                 41
Configuration

    application/config
        config.php
        database.php
        autoload.php




                          42
Configuration

    application/config
        config.php
        database.php
        autoload.php ─── 在程式執行時自動
                          載入模組或函式




                                     43
URLs

    URL segment map to Controller

     index.php/post/show/2385




                                     44
URLs

    URL segment map to Controller

     index.php/post/show/2385


       Controller
                             Argument
                    Method



                                     45
URLs

 class Post extends CI_Controller {

     public function show($id){

         // Get post information

     }

 }

                                      46
Controller
 application/controller/welcome.php:

 class Welcome extends CI_Controller {

        public function index(){

             $this->load->


   view('welcome_message');

        }                                47
Controller
 application/controller/welcome.php:

 class Welcome extends CI_Controller {

        public function index(){

             $this->load->


   view('welcome_message');

        }                                48
Controller
 application/controller/welcome.php:

 class Welcome extends CI_Controller {

        public function index(){

             $this->load->


   view('welcome_message');

        }                                49
Your Own Controller
 controller/hello.php

 class Hello extends CI_Controller {
     public function greeting($id){
          echo “Hello $id”;
     }
 }



                                       50
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
Your Own Controller

 Deny method from URL access


 class Hello extends CI_Controller {
     public function _greeting($id){
         echo “Hello $id”;
     }
 }            Underline

                                       52
View

    位於 application/view/
    由 controller 載入
    Template parser




                            53
View

    application/view/hello.php


 <html><body>
      <h1>
        Hello <?php echo $id;?>
      </h1>
 </html></body>

                                  54
View

    Load view


 function hello($id){
     $data[„id‟] = $id;
     $this->load->view(„hello‟, $data);
 }


                                      55
Template Parser

 <html><body>
   <h1>
     Hello <?php echo $id;?>
   </h1>
 </html></body>         PHP




                               56
Template Parser

 <html><body>
   <h1>
     Hello {id}
   </h1>
 </html></body>




                  57
Template Parser

 function hello($id){
     $this->load->library(„parser‟);
     $data[„id‟] = $id;
     $this->parser->
                  parse(„hello', $data);
 }


                                           58
Model

    Process data in database


 class User extends CI_Model{
      function getUser($uid) { ... }
      function deleteUser($uid) { ... }
 }


                                          59
Model

    Load model in controller


     $this->load->model(„user‟);

     $user = $this->user->getUser(2);




                                    60
Built-in Functions

    Library
        Input
        Template Parser
        File Uploading
    Helper
        URL
        CAPTCHA


                           61
Built-in Functions

    Load
        $this->load->library(„upload‟);
        $this->load->helper(„url‟);


    Use
        $this->upload->data();
        echo site_url();


                                           62
No enough?



             63
Sparks !



           64
Sparks

    Package management system for
     CodeIgniter
    Easy to install
    Lots of useful packages
    Makes you lazy




                                     65
Install Sparks



php -r "$(curl -fsSL http://getsparks.org/go-sparks)"




                                                  66
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 - You're
   on fire!

                                                    67
Using Packages

    Load and call


 $this->load->spark(„redis/0.3.0‟);


 $this->redis->set(„foo‟, „bar‟);




                                      68
More

    CodeIgniter 中文討論區
     http://www.codeigniter.org.tw/forum/


    CodeIgniter Wiki
     http://codeigniter.com/wiki




                                            69
Q & A



        70
Live Debug
     Demo

             71
Thank You



            72

More Related Content

What's hot

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
guoqing75
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain Points
Steven Evatt
 

What's hot (19)

Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
Codeigniter4の比較と検証
Codeigniter4の比較と検証Codeigniter4の比較と検証
Codeigniter4の比較と検証
 
Zend Framework Foundations
Zend Framework FoundationsZend Framework Foundations
Zend Framework Foundations
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Lightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-codeLightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-code
 
Effective CMake
Effective CMakeEffective CMake
Effective CMake
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 
IPC 2015 ZF2rapid
IPC 2015 ZF2rapidIPC 2015 ZF2rapid
IPC 2015 ZF2rapid
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
A quick start on Zend Framework 2
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain Points
 
CMake - Introduction and best practices
CMake - Introduction and best practicesCMake - Introduction and best practices
CMake - Introduction and best practices
 
Zend\Expressive - höher, schneller, weiter
Zend\Expressive - höher, schneller, weiterZend\Expressive - höher, schneller, weiter
Zend\Expressive - höher, schneller, weiter
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressive
 

Similar to Introduction to Codeigniter

Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im ÜberblickEin Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
renebruns
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
Ganesh Kulkarni
 

Similar to Introduction to Codeigniter (20)

Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜
「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜 「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜
「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜
 
CodeIgniter Framework
CodeIgniter FrameworkCodeIgniter Framework
CodeIgniter Framework
 
Review unknown code with static analysis - bredaphp
Review unknown code with static analysis - bredaphpReview unknown code with static analysis - bredaphp
Review unknown code with static analysis - bredaphp
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf
 
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im ÜberblickEin Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Tools
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Introduction to Codeigniter