SlideShare a Scribd company logo
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 (19)

PDF
Dependency Injection in PHP
Kacper Gunia
 
PDF
Codeigniter4の比較と検証
ME iBotch
 
PDF
Zend Framework Foundations
Chuck Reeves
 
PDF
Challenges of container configuration
lutter
 
PDF
Lightweight Developer Provisioning with Gradle and SEU-as-code
Mario-Leander Reimer
 
PDF
Effective CMake
Daniel Pfeifer
 
PDF
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
PPT
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf Conference
 
PDF
Gearman work queue in php
Bo-Yi Wu
 
PPTX
Going native with less coupling: Dependency Injection in C++
Daniele Pallastrelli
 
PDF
IPC 2015 ZF2rapid
Ralf Eggert
 
PDF
Zend Framework 2 - Basic Components
Mateusz Tymek
 
PDF
Perl web frameworks
diego_k
 
PDF
A quick start on Zend Framework 2
Enrico Zimuel
 
PDF
4069180 Caching Performance Lessons From Facebook
guoqing75
 
PPT
Migrating PriceChirp to Rails 3.0: The Pain Points
Steven Evatt
 
PDF
CMake - Introduction and best practices
Daniel Pfeifer
 
PDF
Zend\Expressive - höher, schneller, weiter
Ralf Eggert
 
PDF
Make your application expressive
Christian Varela
 
Dependency Injection in PHP
Kacper Gunia
 
Codeigniter4の比較と検証
ME iBotch
 
Zend Framework Foundations
Chuck Reeves
 
Challenges of container configuration
lutter
 
Lightweight Developer Provisioning with Gradle and SEU-as-code
Mario-Leander Reimer
 
Effective CMake
Daniel Pfeifer
 
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf Conference
 
Gearman work queue in php
Bo-Yi Wu
 
Going native with less coupling: Dependency Injection in C++
Daniele Pallastrelli
 
IPC 2015 ZF2rapid
Ralf Eggert
 
Zend Framework 2 - Basic Components
Mateusz Tymek
 
Perl web frameworks
diego_k
 
A quick start on Zend Framework 2
Enrico Zimuel
 
4069180 Caching Performance Lessons From Facebook
guoqing75
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Steven Evatt
 
CMake - Introduction and best practices
Daniel Pfeifer
 
Zend\Expressive - höher, schneller, weiter
Ralf Eggert
 
Make your application expressive
Christian Varela
 

Similar to Introduction to Codeigniter (20)

PPTX
Introduction to CodeIgniter
Piti Suwannakom
 
PDF
「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜
Makoto Kaga
 
PDF
Review unknown code with static analysis - bredaphp
Damien Seguy
 
PPT
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
PDF
Building Testable PHP Applications
chartjes
 
PDF
Everything as a Code / Александр Тарасов (Одноклассники)
Ontico
 
PDF
Everything as a code
Aleksandr Tarasov
 
ODP
Codegnitorppt
sreedath c g
 
PDF
501 - PHP MYSQL.pdf
AkashGohil10
 
PDF
Excelian hyperledger walkthrough-feb17
Excelian | Luxoft Financial Services
 
PPTX
Python from zero to hero (Twitter Explorer)
Yuriy Senko
 
ODP
Pyramid deployment
Carlos de la Guardia
 
KEY
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
renebruns
 
PPT
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
PDF
PHP QA Tools
rjsmelo
 
PDF
Automate Your Automation | DrupalCon Vienna
Pantheon
 
PDF
Web internship Yii Framework
Noveo
 
KEY
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Martin de Keijzer
 
PPT
Introduction To Code Igniter
Amzad Hossain
 
Introduction to CodeIgniter
Piti Suwannakom
 
「Code igniter」を読もう。〜ソースコードから知る仕様や拡張方法〜
Makoto Kaga
 
Review unknown code with static analysis - bredaphp
Damien Seguy
 
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Building Testable PHP Applications
chartjes
 
Everything as a Code / Александр Тарасов (Одноклассники)
Ontico
 
Everything as a code
Aleksandr Tarasov
 
Codegnitorppt
sreedath c g
 
501 - PHP MYSQL.pdf
AkashGohil10
 
Excelian hyperledger walkthrough-feb17
Excelian | Luxoft Financial Services
 
Python from zero to hero (Twitter Explorer)
Yuriy Senko
 
Pyramid deployment
Carlos de la Guardia
 
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblick
renebruns
 
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
PHP QA Tools
rjsmelo
 
Automate Your Automation | DrupalCon Vienna
Pantheon
 
Web internship Yii Framework
Noveo
 
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Martin de Keijzer
 
Introduction To Code Igniter
Amzad Hossain
 
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Ad

Introduction to Codeigniter