tpphp-5

Embed Size (px)

Citation preview

  • 7/29/2019 tpphp-5

    1/22

    Applications Web - PHPTP-5

    Mauricio Cerda [email protected]://www.loria.fr/~cerdavim/iut

    mailto:[email protected]:[email protected]
  • 7/29/2019 tpphp-5

    2/22

    Aujourd'hui

    Programmation oriente objet

    Utilisation POO Codage UTF/ISO/Latin

    Exercices

  • 7/29/2019 tpphp-5

    3/22

    POO

    Nous avons dj vu PHP, HTML et BDmais, comment travailler tout ensemble?

    HTML

    WWW + PHP (J2EE,ASP)

    Base dedones

  • 7/29/2019 tpphp-5

    4/22

    POO

    Intuition: diviser les problmes (et solutions)en units fonctionnelles

    POO est une abstraction, c'est utile diffrent niveaux (design, programmation,user requirements)

  • 7/29/2019 tpphp-5

    5/22

    POO

    Exemple: le football

  • 7/29/2019 tpphp-5

    6/22

    POO

    Exemple: le football:Player

    team, speed, Point, number

    Ball:Point

    Position,vx,vy

    :Point

    x,y

    GoalKeeper:Player

    luck

    :Field

    size,Player[],Ball4

    Plays

    1

  • 7/29/2019 tpphp-5

    7/22

    POO

    Exemple: le football:Player

    team, speed, Point,number

    :Ball

    Position,vx,vy

    :Point

    x,y

    GoalKeeper:Player

    luck

    :Field

    size,Players[],Ball4

    Plays

    1

    kick(Ball)timeTo(Point)

    IsIn(Point)

    reset()makePlay()printGame()

  • 7/29/2019 tpphp-5

    8/22

    POO

    Comme avec toute technique, POO n'estpas parfait. Exemple, travailler avec desaspects de code (securit, visualisation).

    Avec POO on peut over-design aussi!

  • 7/29/2019 tpphp-5

    9/22

    POO

    Syntax: nom, attributes, fonctions (>php5)

  • 7/29/2019 tpphp-5

    10/22

    POO

    Attributes visibilit: public, protected etprivate (identique a Java)

    Instance: static, const

  • 7/29/2019 tpphp-5

    11/22

    POO

    Fonctions: public, protected, final et private(identique a Java)

    Instance: static, constructor, destructor

  • 7/29/2019 tpphp-5

    12/22

    POO

    Noms de fonction magiques:

    __construct, __destruct

    __call, __callStatic,

    __get, __set,

    __isset, __unset (surcharge),

    __sleep, __wakeup,

    __toString, __set_state

    __clone

  • 7/29/2019 tpphp-5

    13/22

    Utilisation POO

    Qu'est-ce que on peut faire avec OOP? Exemple facile (L'oprateur de rsolution de

    porte :: )

  • 7/29/2019 tpphp-5

    14/22

    Utilisation POO

    Hritage et Polymorphism: problme

  • 7/29/2019 tpphp-5

    15/22

    Utilisation POO

    Hritage et Polymorphism: solution

  • 7/29/2019 tpphp-5

    16/22

    Utilisation POO

    Abstract Class -> structure

    abstract class AbstractClass

    {// Force la classe tendue// dfinir cette mthode

    abstract protected function getValue(); abstract protected

    function prefixValue($prefix);

    // mthode communepublic function printOut() {print $this->getValue() . "\n";

    }}

    class ConcreteClass1 extends

    AbstractClass{

    protected function getValue() {return "ConcreteClass1";

    }

    public function prefixValue($prefix) {return "{$prefix}ConcreteClass1";

    }}

  • 7/29/2019 tpphp-5

    17/22

    Utilisation POO

    Interfaces et implements

  • 7/29/2019 tpphp-5

    18/22

    Codage

    Pourquoi la semaine dernier vous avez vu?:

  • 7/29/2019 tpphp-5

    19/22

    Codage

    La BD est encode (UTF-8, Latin1)

    Le serveur (apache) envoie le html aussiencode (et peut-tre different la BD)

    Le client (firefox,IE) voie le package http,il suivre le serveur et pas les donnes!

  • 7/29/2019 tpphp-5

    20/22

    Exercices

    Maintenant, essayez avec les exercices 6-12 (POO et PHP dans le fichierexercices_2.pdf)

    Attention!!, la dernier session vousaurez une ptite valuation 21/10/2008

    (semblable les exercices de cettutoriel).

  • 7/29/2019 tpphp-5

    21/22

    Configuration MYSQL

    Serveur webetu:

    Sur http://webetu il y a un serveur mysql avecphpmyadmin pour administrer

    Crer votre base de donnes (http://webetu)Tlcharger le fichier:

    http://www.loria.fr/~cerdavim/iut-mcerda.sql

    Avec phpmyadmin faire l'import des donnessur votre BD

    Maintenant vous pouvez faire votre connexionmysql vers webetu, avec php et votre compte

    http://webetu/http://webetu/http://www.loria.fr/~cerdavim/iut-mcerda.sqlhttp://www.loria.fr/~cerdavim/iut-mcerda.sqlhttp://webetu/http://webetu/
  • 7/29/2019 tpphp-5

    22/22

    Configuration PHP

    Windows (serveur webetu):

    Dmarrer -> Excuter -> \\WEBETU\\www

    Sortie Firefox/Explorer:

    http://webetu/~login/votrefichier.php

    Linux

    Modifier en /www/etude/login/votrefichier.php

    Sortie Firefox:http://webetu/~login/votrefichier.php

    http://webetu/~login/votrefichier.phphttp://webetu/~login/votrefichier.phphttp://webetu/~login/votrefichier.phphttp://webetu/~login/votrefichier.php