IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Hiérarchie et surcharge des méthodes [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut Hiérarchie et surcharge des méthodes
    Bonjour, Après quelques mois d'absence, je le remets à PHP...
    Pas évident!
    Bref, j'ai réduit mon application à un petit exemple pour test...
    Mon questionnement est tout à fait d'actualité quand j'ai été surpris d'avoir les mêmes résultats même en commentant l'extends
    Je vous soumets mon petit exemple pour avoir vos commentaires
    Le voici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <?php
    	define("CRLF"       , "<br>\n") ;
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    /**
    * 	FORM constructor
    *
    */	
    		class Form 
    		{	private $cnt = 0 , $form ;
    		
    			function __construct($form)
    			{	$this->form = $form ;
    				$this->cnt	= count($form) ;
    				print("Form|__construct]" . CRLF) ;
    			}
    				
    			
    			function initForm()
    			{   print("Form|initForm]" . CRLF) ;
    				for($i = 0 ; $i < $this->cnt ; $i++) 
    				{	TEXT::initForm() ;
    				}		
    			}
    		}
    
    		class Text //extends Form
    		{	private $fld ;
    		
    			function __construct($fld)
    			{	$this->fld = $fld ;
    				print("Text|__construct][$fld]" . CRLF) ;
    			}
    				
    			function initForm()
    			{   print("Text|initForm]" . CRLF) ;
    			}
    			
    			function filled()
    			{ 	print("Text|filled]" . CRLF) ;
    			}
    		}
    		
    	$cf = new Form	(array	(   new Text  ( 	"prénom"	) ,
      								new Text  ( 	"nom"		) 		
    							)	
    					) ;
    	
    	$cf->initForm() ;
    ?>
    Lequel affiche:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Text|__construct][prénom]
    Text|__construct][nom]
    Form|__construct]
    Form|initForm]
    Text|initForm]
    Text|initForm]
    La méthode Text est supposée être multiple et le tableau $cf contenir différents objet.
    Merci à vous tous
    Esteban

  2. #2
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Bonjour,

    Le résultat est tout à fait normal

    Tu as deux class différentes, donc chaque new appelle le constructeur

    Qd tu dis:
    Mon questionnement est tout à fait d'actualité quand j'ai été surpris d'avoir les mêmes résultats même en commentant l'extends
    C'est parceque tu utilises mal la notion d'héritage et du constructeur.
    Qd tu définis une class extends d'une autre cette dernière lors d'un new, appelera le constructeur de la class mére HORS LA tu redéfinis le constructeur donc pour le new c'est rappé (et tu obtiendra la même chose).

    Si tu redéfinis le constructeur de la class extends d'une autre il faut faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
       public function construct() 
        { 
            parent::__construct(); 
     
            ....
     
        }
    Dans ce cas, il aura une bonne utilisation de ton extends
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  3. #3
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut extends...
    Merci pour ta réponse...
    Mais une petite autre question qui explique sans doute l'erreur PHP
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [25-Jul-2012 09:01:07] PHP Fatal error:  Call to undefined method Form::construct() in F:\WebSites\t1\index.php on line 48
    Comment dois-je spécifier le paramètre $form dans l'appel au constructeur de la classe Parent à partir du constructeur de la classe étendue (Text) ?

    Voici mon code actuel...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    <?php
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //                                      My stuff's                                                                                                   //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //	require_once $_SERVER['DOCUMENT_ROOT'] . "/class/subscribers.php";  
    	define("CRLF"       , "<br>\n") ;
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    /**
    * 	FORM: constructor
    *
    */	
    		class Form 
    		{	private $cnt = 0 , $form ;
    		
    			function __construct($form)
    			{	$this->form = $form ;
    				$this->cnt	= count($form) ;
    				print("Form|__construct]" . CRLF) ;
    			}
    				
    /**
    * 	FORM: initForm
    *
    */			
    			function initForm()
    			{   print("Form|initForm]" . CRLF) ;
    				for($i = 0 ; $i < $this->cnt ; $i++) 
    				{	TEXT::initForm() ;
    				}		
    			}
    		}
    
    		class Text extends Form
    		{	private $fld ;
    
    /**
    * 	TEXT: constructor
    *
    */			
    			function __construct($fld)
    ==> 48			{	parent::construct() ;
    				$this->fld = $fld ;
    				print("Text|__construct][$fld]" . CRLF) ;
    			}
    				
    /**
    * 	TEXT: initForm
    *
    */			function initForm()
    			{   print("Text|initForm]" . CRLF) ;
    			}
    			
    /**
    * 	TEXT: isFilled
    *
    */			function isFilled()
    			{ 	print("Text|isFilled]" . CRLF) ;
    			}
    		}
    		
    	$cf = new Form	(array	(   new Text  ( 	"prénom"	) ,
      								new Text  ( 	"nom"		) 		
    							)	
    					) ;
    	
    	$cf->initForm() ;
    ?>
    Encore merci @toi...
    Esteban

  4. #4
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut Autre question
    Désolé, j'aurai pu ajouter cette question dans ma réponse précédente...

    Sachant que dans le tableau $cf il peut y avoir plusieurs types d'objet, Comment dois-je écrire la fonction initForm du constructeur en fonction du type différent de l'enfant ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    			function initForm()
    			{   print("Form|initForm]" . CRLF) ;
    				for($i = 0 ; $i < $this->cnt ; $i++) 
    				{	TEXT::initForm() ;
    				}		
    			}
    Merci pour cette bête question....
    Esteban

  5. #5
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Sans regarder l'erreur, tu as qd même un problème de conception car:

    (j'imagine que form est un formulaire et txt un champ text) tu ne peux pas faire class Text extends Form car Text devrait être en fait un autre type de formulaire, d'ou ton problème de passage de paramétre.

    Et puis la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $cf = new Form	(array	(   new Text  (  ....
    c'est pas possible dans ton cas, ce serait plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    $cf = new Form (paramétre de la form);
    $cf->addText ("prénom");
    $cf->addText ("nom");
    Donc à modifier ...

    Enfin pour l'erreur en elle même:
    Call to undefined method Form::construct() car tu as une méthode construct avec un argument. Il faudrait définir dans la class form une méthode construct sans arguments et une avec un argument (dans ce cas la form).
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  6. #6
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut Autre question & extends
    Merci pour ta réponse, je vais revoir le tout en fonction de tes commentaires
    Pour la dernière question, j'ai entre-temps trouvé une solution

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    			
    function initForm()
    			{   print("Form[initForm]" . CRLF) ;
    				for($i = 0 ; $i < $this->cnt ; $i++) 
    				{	$this->form[$i]->initForm() ;
    				}		
    			}
    Merci @toi
    Esteban

  7. #7
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Pour bien refaire tes classes, il faudrait que tu nous fasses un topo de ce que tu veux faire et un exemple ou deux car là je crois que se mélange les pinceaux
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  8. #8
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut Autre question & extends
    Le but final est comme tu l'as deviné - de faire un formulaire avec validation de plusieurs types de donnée...
    J'ai repris un script écrit il y a plusieurs années - car ne trouve sur le net ce qu'il me conviendrait exactement alors apprendre pour apprendre...

    Voici un exemple d'utilisation:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
     
    /**
    * 	FIELD(validation) constructor
    *
    */	
    	$prenom 	= new Text   	( 	"prénom"	,  	MUST , 	aE    	, 	WARN 	,  3, 30   						) ;
    	$nom    	= new Text 		( 	"nom"		,   MUST , 	aNumE   , 	WARN 	,  3, 30 						) ;
    	$numero    	= new Integer	( 	"numero"	,   MUST , 	INTEGER , 	WARN 	,  3,  5 						) ;
    	$boite    	= new Text      (   "boite"	    ,   OPT  , 	aNum    , 	WARN 	,  1,  5 						) ;
    	$pass 		= new Password  (	"pass" 		, 	MUST , 	aNum 	, 	WARN 	,  6 , 8 						) ;    	
    	$cpass 		= new Password  (	"cpass" 	, 	MUST , 	aNum 	, 	WARN 	,  6 , 8 						) ;    	
    	$email  	= new Email 	(	"email"		, 	MUST , 				WARN 	,  8, 30 						) ;
    	$cemail  	= new Email 	(	"cemail"	, 	MUST , 				WARN 	,  8, 30 						) ;
    	$phone 		= new Phone  	(   "phone"		, 	MUST , 				WARN	, 10, 10 						) ;   
    	$zip    	= new Integer	( 	"zip"	    ,   MUST , 	INTEGER , 	WARN 	,  5,  5 						) ;
    	$phone 		= new Phone  	(   "phone"		, 	MUST , 	PHONE	,	WARN	, 10, 10 						) ;   
    	$comment   	= new Textarea	( 	"comment"	,   MUST , 	aNumE   , 	WARN 	,  3, 30 						) ;
    /*
    	$cemail  	= new Email 	(	"cemail"	, 	MUST , 			WARN 	,  3, 30 						) ;
    	$phone 		= new Phone  	(   "phone"		, 	MUST , 			WARN	, 10, 10 						) ;   
    	$pass 		= new Password  (	"pass" 		, 	MUST , 	aNum , 	WARN 	,  6 , 8 						) ;    	
    	$cpass 		= new Password  (   "cpass" 	, 	MUST , 	aNum , 	WARN 	,  6 , 8 						) ;
    	$type 	    = new DontSel   (   "type"  	,  	MUST , 	 	 	WARN 	,   $type 						) ;
    	$area  		= new Textarea  (   "area" 		,	MUST , aNumE , 	WARN 	, 10, 500 						) ;
    	$little		= new Little   	(   "little" 	,	MUST ,      	WARN 	, 10    						) ;
    	$great  	= new Greater 	(   "greater"	, 	MUST ,   	 	WARN 	, 500 							) ;
    	$reg		= new RegExp 	(   "regexp" 	,	MUST ,   	 	WARN 	, "" 							) ;
    	$dontsel   	= new DontSel 	(   "dontsel" 	,	MUST ,   	 	WARN 	, 0 							) ;
    	$samepass   = new EqualPass (   "equalpass" ,	MUST ,   	 	WARN 	, $pass  , $cpass 		 		) ;	
    	$samemail   = new EqualMail (   "equalmail" ,	MUST ,   	 	WARN 	, $email , $cemail 		 		) ;
    	$function   = new Funct     (   "function " ,	MUST ,   	 	WARN 	, $address , "msgT" , "msgF" 	) ;
    */				
     
    	$form = array   (   $prenom 	,
    						$nom    	,	
    						$numero 	,
    						$boite      ,
    						$pass 		,	
    						$cpass 		,	
    						$phone 		,	
    						$email 		,
    						$cemail 	,
    						$zip		,
    						$comment
    					);
    /*						$cemail 	, 	
    						$phone 		,	
    						$pass 		,	
    						$cpass 		,
    						$type 		,    
    						$area  		,	
    						$little		,	
    						$great  	,	
    						$reg		,	
    						$dontsel	,   	
    						$samepass 	,  
    						$samemail 	,
    					    $function 
    */
    	$cf = new Form($form);
     
       	if (isset($_POST['SUBMIT']))
    		{	user_error("POST SUBMIT CATCHED" , E_USER_NOTICE) ;
    			if ($cf->isFormValid())
    				{	# Formulaire valide
        				# Instruction ...
        			}
        		else 
    				{	# Sinon ...
        		 		# Instruction ...
    				}
     
        	}
    La forme HTML...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
     
    <?php
    //
    //  Form definition (for validation purposes)
    //
    ?>
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="CheckForm">
    <table width="615" border="0">
      <tr>
        <td>&nbsp;</td>
        <td colspan="6"><div align="center" class="style1">Validation de votre formulaire </div></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="8"><hr /></td>
      </tr>
      <?php
      		if (!$cf->isFormValid())
    			{
      ?>
      <tr>
        <td height="104">&nbsp;</td>
        <td colspan="6" align="center">
            <textarea name="textarea2" cols="70" rows="5"><?php echo $cf->getStackError()?></textarea>     </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="8"><hr /></td>
      </tr>
      <?php
      			}
      ?>
      <tr>
        <td width="60">Prénom</td>
        <td colspan="3">
    		<input type="text" name="prenom" maxlength="32" value="<?php if (isset($_POST['prenom'])) echo $_POST['prenom'] ?>"/>	</td>
        <td width="127"><div align="center">Nom</div></td>
        <td width="149"><input type="text" name="nom"   maxlength="32" value="<?php if (isset($_POST['nom'])) echo $_POST['nom'] ?>" /></td>
        <td width="46">&nbsp;</td>
        <td width="62">&nbsp;</td>
      </tr>
      <tr>
        <td>Email</td>
        <td colspan="3"><input type="text" name="email"  maxlength="32" value="<?php if (isset($_POST['email'])) echo $_POST['email'] ?>" /></td>
        <td><div align="center">Conf Email</div></td>
        <td><input type="text" name="cemail" maxlength="32" value="<?php if (isset($_POST['cemail'])) echo $_POST['cemail'] ?>" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
     
      <tr>
        <td>Phone</td>
        <td colspan="3"><input type="text" name="phone"  maxlength="10" value="<?php if (isset($_POST['phone'])) echo $_POST['phone'] ?>" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Password</td>
        <td><input name="pass" type="password" value="<?php if (isset($_POST['pass'])) echo $_POST['pass'] ?>" size="8"   maxlength="8" /></td>
        <td colspan="2">&nbsp;</td>
     
        <td><div align="center">Conf password</div></td>
        <td colspan="2"><input name="cpass" type="password" value="<?php if (isset($_POST['cpass'])) echo $_POST['cpass'] ?>" size="8"  maxlength="8" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>N°  </td>
        <td width="50">
          <input name="numero" type="text" size="5" maxlength="5"  value="<?php if (isset($_POST['numero'])) echo $_POST['numero'] ?>" />   	</td>
        <td width="50"><div align="center">Bte</div></td>
        <td width="30"><input name="boite" type="text" id="boite" size="5" maxlength="5" value="<?php if (isset($_POST['boite'])) echo $_POST['boite'] ?>"/></td>
        <td><div align="center">Voie</div></td>
        <td>    	
    		<?php
            	form_select($sel_typerue , $name="typerue" ) ; 
    		?>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Zip</td>
        <td colspan="3">
          <input name="zip" type="text" id="zip" size="5" maxlength="5" value="<?php if (isset($_POST['zip'])) echo $_POST['zip'] ?>"/>
        </td>
        <td><div align="center">Ville</div></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Radio bouton</td>
        <td colspan="3">				
    		<?php 
    			form_radio($nonoui, $name="cee", $direct="H") ; 
    		?>	
        </td>           
      <div align="center"></div>
        <td>Question secrète </td>
        <td>	                   	
    		<?php					  
    			form_select($sel_question , $name="question" ) ; 
    		?>	</td>
        <td>&nbsp;</td>
        <td width="3">&nbsp;</td>
      </tr>
      <tr>
        <td>Pays</td>
        <td colspan="3">
        	<?php
            	form_select($sel_country , $name="country" ) ; 
    		?>
            </td>
        <td>Loisir</td>
        <td colspan="2">
    		<?php
    			checkbox($sel_loisir,$name="loisir",$direct="H") ;
    		?>	</td>
        <td>&nbsp;</td>
      </tr>
     
      <tr>
        <td>Text</td>
        <td colspan="6">
        	<div align="center">
        	  	<textarea name="comment" cols="70" rows="12"><?php if (isset($_POST["comment"])) echo $_POST["comment"] ?></textarea>
       	    </div>	</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="8"><hr/></td>
      </tr>
      <tr>
        <td><input type="reset"  name="effacer"   value="Effacer"/></td>
        <td colspan="6" align="center">
          <input type="text"   size=60 name="message"   value="<?php if (isset($cf)) echo $cf->getMessage() ?>" />    </td>
        <td><input type="submit" name="SUBMIT"   value="Envoyer"/></td>
      </tr>
    </table>
    </form>
     
    </body>
    </html>
    Voilà, j'espère avoir répondu à ta question
    Merci pour tes suggestions !
    Esteban

  9. #9
    Débutant Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Points : 170
    Points
    170
    Par défaut Autre question & extends
    J'ai effectué une 1ère batterie de modif
    Puis-je avoir tes commentaires ?
    Voici mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    <?php
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //                                      My stuff's                                                                                                   //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //	require_once $_SERVER['DOCUMENT_ROOT'] . "/class/subscribers.php";  
    	define("CRLF"       , "<br>\n") ;
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //                                      FORM                                                                                                         //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    /**
    * 	FORM: constructor
    *
    */	
    		class Form 
    		{	private $cnt = 0 , $form ;
    		
    			function __construct()
    			{	$this->form = NULL ;
    				$this->cnt	= 0 ;
    				print("Form[__construct]" . CRLF) ;
    			}
    				
    /**
    * 	FORM: initForm
    *
    */			
    			function initForm()
    			{   print("Form[initForm]" . CRLF) ;
    				for($i = 0 ; $i < $this->cnt ; $i++) 
    ==> 38				{	$this->form[$i]->initForm() ;
    				}		
    			}
    				
    /**
    * 	FORM: addText
    *
    */			
    			function addText($p1)
    			{   print("Form[addText]" . CRLF) ;
    				$this->cnt++ ;
    				$this->form[$this->cnt] = new Text($p1) ;
    			}
    				
    /**
    * 	FORM: addText
    *
    */			
    			function addString($p1)
    			{   print("Form[addString]" . CRLF) ;
    				$this->cnt++ ;
    				$this->form[$this->cnt] = new String($p1) ;
    			}
    		}
    
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //                                      TEXT                                                                                                         //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    /**
    * 	TEXT: constructor
    *
    */			
    		class Text //extends Form
    		{	private $fld ;
    
    			function __construct($fld)
    			{	//parent::construct() ;
    				$this->fld = $fld ;
    				print("Text[__construct][$fld]" . CRLF) ;
    			}
    				
    /**
    * 	TEXT: initForm
    *
    */			function initForm()
    			{   print("Text[initForm]" . CRLF) ;
    			}
    			
    /**
    * 	TEXT: isFilled
    *
    */			function isFilled()
    			{ 	print("Text[isFilled]" . CRLF) ;
    			}
    		}
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    //                                      STRING                                                                                                       //
    // ------------------------------------------------------------------------------------------------------------------------------------------------- //
    /**
    * 	STRING: constructor
    *
    */			
    		class String //extends Form
    		{	private $fld ;
    
    			function __construct($fld)
    			{	//parent::construct() ;
    				$this->fld = $fld ;
    				print("String[__construct][$fld]" . CRLF) ;
    			}
    				
    /**
    * 	STRING: initForm
    *
    */			function initForm()
    			{   print("String[initForm]" . CRLF) ;
    			}
    			
    /**
    * 	STRING: isFilled
    *
    */			function isFilled()
    			{ 	print("String[isFilled]" . CRLF) ;
    			}
    		}
    		
    	$cf = new Form	() ;
    	
    	$cf->addText  ( "prénom"	) ;
    	$cf->addString(	"nom"	 	) ;
    	$cf->initForm() ;
    ?>
    Sachant qu'il me reste une erreur PHP...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    [25-Jul-2012 09:59:14] PHP Fatal error:  Call to a member function initForm() on a non-object in F:\WebSites\t1\index.php on line 38
    Je pause un peu et m'y remet d'ici 1/2 h
    Merci bcp
    Esteban

  10. #10
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Oui bein tu as pas besoin de faire d'extends

    Tu as ta classe form avec dedans un tableau d'objets (Text, Password, Email etc ...).

    Le seul petit soucis, c'est de savoir à chaque fois comment initiliser l'objet, la meilleure façons semble de passer aussi le type de l'objet ...
    Exemple en gardant un tableau simple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $form = array   (   'text',  $prenom , 'text', $nom, 'int', $numero ... )
    ou par une matrice (tableau deux dimenssion)

    Ensuite lors du $cf = new Form($form); tu modifies le constructeur de ta class form avec du code genre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    //Boucle sur tous les élements
    // Si type text alors $arrayObj[index] = new typeObj();
    // ect ...
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 09/11/2012, 10h59
  2. Réponses: 4
    Dernier message: 14/07/2009, 18h11
  3. surcharge des méthodes
    Par etoile_de_vie dans le forum Services Web
    Réponses: 1
    Dernier message: 23/12/2008, 11h25
  4. Surcharge des méthodes et déploiement du webservice
    Par hacksi dans le forum Services Web
    Réponses: 1
    Dernier message: 03/04/2008, 10h06
  5. Surcharger des méthodes
    Par Ggamer dans le forum wxPython
    Réponses: 3
    Dernier message: 16/11/2007, 20h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo