SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
Intro to MVC Development in PHP
Ed Finkler • http://funkatron.com • @funkatron
#tekmvc • php|tek 2009
Thee Agenda
All About MVC
Why CodeIgniter?
The CI MVC Model
CI Basics
Running CI out of the box
Making a basic web app
Making a web api
Libraries, components, logging and caching
All About MVC
                http://www.flickr.com/photos/airship/118352487/
What is MVC?
What is MVC?

1979, Norwegian, Xerox Parc
Give user the impression of interacting directly with
data
Used in GUI apps first
http://short.ie/g95zua
A Diagram

            Controller




    View                 Model
The Model


quot;Represent knowledgequot;
The data/business functionality
The View


Visual representation of the model
The screens and widgets of app
Gets data from model & updates model
The Controller


 Link between user and system
 Responsible for intercepting user input
 Passes user input to view via messages
Why Does
MVC Help?
Separation of concerns



Don't mix your chocolate with my peanut butter
quot;Swappabilityquot;



 Avoid tight coupling
MVC is not magic fairy dust


    But understanding it and using it
    can make you a better developer
Variations on
MVC


 http://short.ie/k2f9rk

                          http://www.flickr.com/photos/stevem78/2975614995/
MVP
Model-View-Presenter (Dolphin Smalltalk variant)
  Presenter primarily updates model


                     Presenter




       View                            Model
PAC
      Presentation-Abstraction-Controller

         Presentation                        Control                     Model


  Presentation             Control            Model


                                                Presentation           Control        Model




Presentation     Control             Model              Presentation        Control     Model
Light vs Heavy



Where does the logic go?
Event-driven vs direct calls



 Observer pattern
http://www.flickr.com/photos/alternatewords/2332580309/



Why CodeIgniter?
Why not CakePHP or Zend
Framework or Limonade or
Symfony or Solar or Kohana
or Zoop or Yii or Akelos or
PHP on Trax or Prado or
Seagull?
Because you've gotta pick
one, dammit
All of them have value*



                          * except Zend Framework
That being said, CI is…
 Easy to understand
 Simple
   doesn't require advanced OOP
 Doesn't force lots of conventions
 Plays well with others
 Quick to get up and running
 Good docs and great community
 Backed by invested entity (http://ellislab.com)
CodeIgniter MVC
Implementation
More of a Passive View
Pattern
                     Controller




        View                      Model



http://short.ie/5o7eg4
CI application flow




         Stolen from CI user guide
App components
Front controller   Helper
Routing            Plugin
Security           Scripts
Controller         View
Model              Caching
Library
Front controller



 index.php
Routing
http://domain.com/index.php/controller/method/param



          class Search extends Controller
          {

              public function single($id)
              {
                 // [...]
              }
          }
Security



 Filtering or blocking unsafe input
Controller
The core of everything      <?php
                            class Site extends Controller {

 quot;Heavyquot;: you could do           function Site() {
                                     parent::Controller();
 everything in controller            $this->load->library('session');
                                 }
public methods are               function index() {
available as actions from            // mletters model is auto-loaded
                                     $rows = $this->mletters->getMany(10);
URL                                  $data['rows'] = $this->_prepData($rows);
                                     $this->load->view('index', $data);
                                 }
private methods prefixed
with “_”                         function _prepData($rows) {
                                     // do some cleanup on the data…
                                 }
                            ?>
Model
   ActiveRecord pattern available, not required
   Query binding

$sql = quot;SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?quot;;
$this->db->query($sql, array(3, 'live', 'Rick'));



   Don't like the DB layer? Use something else
     Zend_DB, Doctrine, DataMapper (http://bit.ly/
     datamapper), IgniteRecord (http://bit.ly/igrec) …
Library



 A class designed to work on related tasks
Helper
 Procedural funcs, grouped by file
 Mostly for views; available in controllers

  /**
    * Plural
    *
    * Takes a singular word and makes it plural
    *
    * @access public
    * @param    string
    * @param    bool
    * @return str
    */
  function plural($str, $force = FALSE)
  {
       // [...]
  }
Plugin
  Single procedural function
  More extensive functionality than helper

  $vals = array(
                   'word'         =>   'Random word',
                   'img_path'     =>   './captcha/',
                   'img_url'      =>   'http://example.com/captcha/',
                   'font_path'    =>   './system/fonts/texb.ttf',
                   'img_width'    =>   '150',
                   'img_height'   =>   30,
                   'expiration'   =>   7200
              );

  $cap = create_captcha($vals);
  echo $cap['image'];
Script



Other scripts the CI app might use
View
          Build response to client
          CI Views are limited
          Uses plain PHP as templating lang
<?php foreach ($rows as $row): ?>
    <li class=quot;letterquot;>
        <div class=quot;bodyquot;>
            <h3>Dear Zend,</h3>
            <p><?=$row->body?></p>
        </div>
        <div class=quot;metaquot;>
            <div class=quot;postedquot;>
                <a href=quot;<?=site_url('/site/single/'.$row->id)?>quot;>Posted <?=$row->posted?></a>
            </div>
            <div class=quot;favoritequot;>Liked by <?=$row->favorite_count?> person(s).
                <a href=quot;<?=site_url('/site/favorite/'.$row->id)?>quot;>I like this</a>
            </div>
        </div>
    </li>
<?php endforeach ?>
View
  Optional template markup
$this->load->library('parser');                 <html>
$this->parser->parse('blog_template', $data);   <head>
                                                <title>{blog_title}</title>
                                                </head>
                                                <body>

                                                    <h3>{blog_heading}</h3>

                                                    {blog_entries}
                                                        <h5>{title}</h5>
                                                        <p>{body}</p>
  Want a heavier template lang?                     {/blog_entries}
  Use one.                                      </body>
                                                </html>
Caching


Saves response to file
Serves up file contents if cache not expired
CI Basics


            http://www.flickr.com/photos/canoafurada/395304306/
CI Structure
                                          front controller
                            index.php     points to system and
                                          application folders




        system                            application

        base classes &                  app-specific classes
   built-in functionality               & functionality
CI Structure
default layout
CI Structure
custom layout
 only index.php is under
 document root
The CI Object



$this inside controllers
The loader



$this->load->{view|library|model|helper|etc}('name');
CI Out of the box
The Welcome App

Put CI on the server
Load it in the browser
Why does Welcome load?
How URLs map
Trace with Xdebug/MacGDBp
Making a web application
Population estimates DB

Get our data from Numbrary: http://short.ie/w3f6h3)
Make a new controller
Change the default route
Config DB settings
Make a model
Make a view
Make fancier views
Make a web API
                 http://www.flickr.com/photos/dunechaser/2429621774/
Web API for pop. est. DB


Let users query our DB via HTTP
Return results on JSON or serialized PHP
http://www.flickr.com/photos/metaphorge/515054465/



Libraries, Components,
Logging and Caching
Autoloading



Make certain libs, models, helpers, etc available
automatically
Libraries
 Extending core libs
   application/libraries/MY_Library.php
 Replacing core libs
   application/libraries/CI_Library.php
 Creating your own libs
   application/libraries/Library.php
   Constructor: Library();
Helpers

Make your own
  application/helpers/name_helper.php
Add to existing
  application/helpers/MY_name_helper.php
Example: PHP lang helper
Using non-CI components

The CI Way
  Examples: Simplepie, Markdown
The dirty, bad way
  require() that jazz
Caching


set cache path in config
make dir writable
enable caching in controller methods
Logging


set path in config
make dir writable
manual logging: log_message(level, msg)
Error handling


 CI uses it's own error handler
 Can block expected behavior
 Example
Questions?
                     http://www.flickr.com/photos/deadhorse/508559841/




@funkatron/#tekmvc
coj@funkatron.com

Weitere ähnliche Inhalte

Was ist angesagt?

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friendsGood Robot
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsThe Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsSharon Chen
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.tothepointIT
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Stéphane Bégaudeau
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 

Was ist angesagt? (20)

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Angularjs
AngularjsAngularjs
Angularjs
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
Introduction to CakePHP
Introduction to CakePHPIntroduction to CakePHP
Introduction to CakePHP
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsThe Django Book - Chapter 5: Models
The Django Book - Chapter 5: Models
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
 
Tango with django
Tango with djangoTango with django
Tango with django
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.Using Renderless Components in Vue.js during your software development.
Using Renderless Components in Vue.js during your software development.
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 

Andere mochten auch

PHP MVC Tutorial 2
PHP MVC Tutorial 2PHP MVC Tutorial 2
PHP MVC Tutorial 2Yang Bruce
 
Why to choose laravel framework
Why to choose laravel frameworkWhy to choose laravel framework
Why to choose laravel frameworkBo-Yi Wu
 
How to choose web framework
How to choose web frameworkHow to choose web framework
How to choose web frameworkBo-Yi Wu
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The BasicsIlio Catallo
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
PHP & JavaScript & CSS Coding style
PHP & JavaScript & CSS Coding stylePHP & JavaScript & CSS Coding style
PHP & JavaScript & CSS Coding styleBo-Yi Wu
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
Arquitectura 3 Capas
Arquitectura 3 CapasArquitectura 3 Capas
Arquitectura 3 CapasFani Calle
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP ArraysAhmed Swilam
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 

Andere mochten auch (20)

PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
 
PHP MVC Tutorial 2
PHP MVC Tutorial 2PHP MVC Tutorial 2
PHP MVC Tutorial 2
 
Why to choose laravel framework
Why to choose laravel frameworkWhy to choose laravel framework
Why to choose laravel framework
 
PAC
PACPAC
PAC
 
Unit 6
Unit 6Unit 6
Unit 6
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Unit 5
Unit 5Unit 5
Unit 5
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
How to choose web framework
How to choose web frameworkHow to choose web framework
How to choose web framework
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
PHP & JavaScript & CSS Coding style
PHP & JavaScript & CSS Coding stylePHP & JavaScript & CSS Coding style
PHP & JavaScript & CSS Coding style
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Arquitectura 3 Capas
Arquitectura 3 CapasArquitectura 3 Capas
Arquitectura 3 Capas
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 

Ähnlich wie Intro To Mvc Development In Php

Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplicationolegmmiller
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Compare Infobase Limited
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBo-Yi Wu
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniternicdev
 
Coder Presentation Szeged
Coder Presentation SzegedCoder Presentation Szeged
Coder Presentation SzegedDoug Green
 
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.frameworkHanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.frameworkNguyen Duc Phu
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 

Ähnlich wie Intro To Mvc Development In Php (20)

Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
I Love codeigniter, You?
I Love codeigniter, You?I Love codeigniter, You?
I Love codeigniter, You?
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
 
Coder Presentation Szeged
Coder Presentation SzegedCoder Presentation Szeged
Coder Presentation Szeged
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.frameworkHanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 

Mehr von funkatron

Building mobile apps with JavaScript and PHP
Building mobile apps with JavaScript and PHPBuilding mobile apps with JavaScript and PHP
Building mobile apps with JavaScript and PHPfunkatron
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developersfunkatron
 
Building RIAs with CodeIgniter and JavaScript
Building RIAs with CodeIgniter and JavaScriptBuilding RIAs with CodeIgniter and JavaScript
Building RIAs with CodeIgniter and JavaScriptfunkatron
 
Secure PHP Development with Inspekt
Secure PHP Development with InspektSecure PHP Development with Inspekt
Secure PHP Development with Inspektfunkatron
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developersfunkatron
 
Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09funkatron
 
Building Desktop RIAs With PHP And JavaScript
Building Desktop RIAs With PHP And JavaScriptBuilding Desktop RIAs With PHP And JavaScript
Building Desktop RIAs With PHP And JavaScriptfunkatron
 
Building Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with  PHP, HTML & Javascript  in AIRBuilding Desktop RIAs with  PHP, HTML & Javascript  in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIRfunkatron
 
Securing the PHP Environment with PHPSecInfo - OSCON 2008
Securing the PHP Environment with PHPSecInfo - OSCON 2008Securing the PHP Environment with PHPSecInfo - OSCON 2008
Securing the PHP Environment with PHPSecInfo - OSCON 2008funkatron
 
Building Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIRBuilding Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIRfunkatron
 
Securing the PHP Environment with PHPSecInfo
Securing the PHP Environment with PHPSecInfoSecuring the PHP Environment with PHPSecInfo
Securing the PHP Environment with PHPSecInfofunkatron
 

Mehr von funkatron (11)

Building mobile apps with JavaScript and PHP
Building mobile apps with JavaScript and PHPBuilding mobile apps with JavaScript and PHP
Building mobile apps with JavaScript and PHP
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Building RIAs with CodeIgniter and JavaScript
Building RIAs with CodeIgniter and JavaScriptBuilding RIAs with CodeIgniter and JavaScript
Building RIAs with CodeIgniter and JavaScript
 
Secure PHP Development with Inspekt
Secure PHP Development with InspektSecure PHP Development with Inspekt
Secure PHP Development with Inspekt
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09
 
Building Desktop RIAs With PHP And JavaScript
Building Desktop RIAs With PHP And JavaScriptBuilding Desktop RIAs With PHP And JavaScript
Building Desktop RIAs With PHP And JavaScript
 
Building Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with  PHP, HTML & Javascript  in AIRBuilding Desktop RIAs with  PHP, HTML & Javascript  in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIR
 
Securing the PHP Environment with PHPSecInfo - OSCON 2008
Securing the PHP Environment with PHPSecInfo - OSCON 2008Securing the PHP Environment with PHPSecInfo - OSCON 2008
Securing the PHP Environment with PHPSecInfo - OSCON 2008
 
Building Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIRBuilding Desktop RIAs with PHP, HTML & Javascript in AIR
Building Desktop RIAs with PHP, HTML & Javascript in AIR
 
Securing the PHP Environment with PHPSecInfo
Securing the PHP Environment with PHPSecInfoSecuring the PHP Environment with PHPSecInfo
Securing the PHP Environment with PHPSecInfo
 

Kürzlich hochgeladen

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Intro To Mvc Development In Php

  • 1. Intro to MVC Development in PHP Ed Finkler • http://funkatron.com • @funkatron #tekmvc • php|tek 2009
  • 2. Thee Agenda All About MVC Why CodeIgniter? The CI MVC Model CI Basics Running CI out of the box Making a basic web app Making a web api Libraries, components, logging and caching
  • 3. All About MVC http://www.flickr.com/photos/airship/118352487/
  • 5. What is MVC? 1979, Norwegian, Xerox Parc Give user the impression of interacting directly with data Used in GUI apps first http://short.ie/g95zua
  • 6. A Diagram Controller View Model
  • 7. The Model quot;Represent knowledgequot; The data/business functionality
  • 8. The View Visual representation of the model The screens and widgets of app Gets data from model & updates model
  • 9. The Controller Link between user and system Responsible for intercepting user input Passes user input to view via messages
  • 11. Separation of concerns Don't mix your chocolate with my peanut butter
  • 13. MVC is not magic fairy dust But understanding it and using it can make you a better developer
  • 14. Variations on MVC http://short.ie/k2f9rk http://www.flickr.com/photos/stevem78/2975614995/
  • 15. MVP Model-View-Presenter (Dolphin Smalltalk variant) Presenter primarily updates model Presenter View Model
  • 16. PAC Presentation-Abstraction-Controller Presentation Control Model Presentation Control Model Presentation Control Model Presentation Control Model Presentation Control Model
  • 17. Light vs Heavy Where does the logic go?
  • 18. Event-driven vs direct calls Observer pattern
  • 20. Why not CakePHP or Zend Framework or Limonade or Symfony or Solar or Kohana or Zoop or Yii or Akelos or PHP on Trax or Prado or Seagull?
  • 21. Because you've gotta pick one, dammit
  • 22. All of them have value* * except Zend Framework
  • 23. That being said, CI is… Easy to understand Simple doesn't require advanced OOP Doesn't force lots of conventions Plays well with others Quick to get up and running Good docs and great community Backed by invested entity (http://ellislab.com)
  • 25. More of a Passive View Pattern Controller View Model http://short.ie/5o7eg4
  • 26. CI application flow Stolen from CI user guide
  • 27. App components Front controller Helper Routing Plugin Security Scripts Controller View Model Caching Library
  • 29. Routing http://domain.com/index.php/controller/method/param class Search extends Controller { public function single($id) { // [...] } }
  • 30. Security Filtering or blocking unsafe input
  • 31. Controller The core of everything <?php class Site extends Controller { quot;Heavyquot;: you could do function Site() { parent::Controller(); everything in controller $this->load->library('session'); } public methods are function index() { available as actions from // mletters model is auto-loaded $rows = $this->mletters->getMany(10); URL $data['rows'] = $this->_prepData($rows); $this->load->view('index', $data); } private methods prefixed with “_” function _prepData($rows) { // do some cleanup on the data… } ?>
  • 32. Model ActiveRecord pattern available, not required Query binding $sql = quot;SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?quot;; $this->db->query($sql, array(3, 'live', 'Rick')); Don't like the DB layer? Use something else Zend_DB, Doctrine, DataMapper (http://bit.ly/ datamapper), IgniteRecord (http://bit.ly/igrec) …
  • 33. Library A class designed to work on related tasks
  • 34. Helper Procedural funcs, grouped by file Mostly for views; available in controllers /** * Plural * * Takes a singular word and makes it plural * * @access public * @param string * @param bool * @return str */ function plural($str, $force = FALSE) { // [...] }
  • 35. Plugin Single procedural function More extensive functionality than helper $vals = array( 'word' => 'Random word', 'img_path' => './captcha/', 'img_url' => 'http://example.com/captcha/', 'font_path' => './system/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, 'expiration' => 7200 ); $cap = create_captcha($vals); echo $cap['image'];
  • 36. Script Other scripts the CI app might use
  • 37. View Build response to client CI Views are limited Uses plain PHP as templating lang <?php foreach ($rows as $row): ?> <li class=quot;letterquot;> <div class=quot;bodyquot;> <h3>Dear Zend,</h3> <p><?=$row->body?></p> </div> <div class=quot;metaquot;> <div class=quot;postedquot;> <a href=quot;<?=site_url('/site/single/'.$row->id)?>quot;>Posted <?=$row->posted?></a> </div> <div class=quot;favoritequot;>Liked by <?=$row->favorite_count?> person(s). <a href=quot;<?=site_url('/site/favorite/'.$row->id)?>quot;>I like this</a> </div> </div> </li> <?php endforeach ?>
  • 38. View Optional template markup $this->load->library('parser'); <html> $this->parser->parse('blog_template', $data); <head> <title>{blog_title}</title> </head> <body> <h3>{blog_heading}</h3> {blog_entries} <h5>{title}</h5> <p>{body}</p> Want a heavier template lang? {/blog_entries} Use one. </body> </html>
  • 39. Caching Saves response to file Serves up file contents if cache not expired
  • 40. CI Basics http://www.flickr.com/photos/canoafurada/395304306/
  • 41. CI Structure front controller index.php points to system and application folders system application base classes & app-specific classes built-in functionality & functionality
  • 43. CI Structure custom layout only index.php is under document root
  • 44. The CI Object $this inside controllers
  • 46. CI Out of the box
  • 47. The Welcome App Put CI on the server Load it in the browser Why does Welcome load? How URLs map Trace with Xdebug/MacGDBp
  • 48. Making a web application
  • 49. Population estimates DB Get our data from Numbrary: http://short.ie/w3f6h3) Make a new controller Change the default route Config DB settings Make a model Make a view Make fancier views
  • 50. Make a web API http://www.flickr.com/photos/dunechaser/2429621774/
  • 51. Web API for pop. est. DB Let users query our DB via HTTP Return results on JSON or serialized PHP
  • 53. Autoloading Make certain libs, models, helpers, etc available automatically
  • 54. Libraries Extending core libs application/libraries/MY_Library.php Replacing core libs application/libraries/CI_Library.php Creating your own libs application/libraries/Library.php Constructor: Library();
  • 55. Helpers Make your own application/helpers/name_helper.php Add to existing application/helpers/MY_name_helper.php Example: PHP lang helper
  • 56. Using non-CI components The CI Way Examples: Simplepie, Markdown The dirty, bad way require() that jazz
  • 57. Caching set cache path in config make dir writable enable caching in controller methods
  • 58. Logging set path in config make dir writable manual logging: log_message(level, msg)
  • 59. Error handling CI uses it's own error handler Can block expected behavior Example
  • 60. Questions? http://www.flickr.com/photos/deadhorse/508559841/ @funkatron/#tekmvc coj@funkatron.com