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

Langage PHP Discussion :

assignation PHP4 attribut de class


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné Avatar de XtofRoland
    Profil pro
    Inscrit en
    Août 2005
    Messages
    357
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2005
    Messages : 357
    Par défaut assignation PHP4 attribut de class
    je réécris une class qui devient trop complexe.
    je delègue a la classe row une partie du travail.
    la partie en gras
    EDIT le gras ne se marque pas ds le code: CRTL + F (]b[)
    me pose problème (si il reste d'autres fautes, c'est normal, je n'ai pas encore finit l'adaptation)
    j'essaye d'assigner une valeur a la var label de ma class row, mais l'assignation ne se fait pas.
    Il n'y a pas de message d'erreur.

    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    <?
    //$obj->addCSS("f.css");
     
    define("CONSULT", 0);
    define("MODIFY", 1);
    define("ADD", 2);
     
    class row{
    	/*
    		
    	*/
    	var $label      = ""; //
    	var $fieldName  = ""; //nom du champs en db
    	var $fieldLen   = ""; 
    	var $fieldType  = "";
    	var $fieldValue = "";
    	var $fieldErrMsg= "";
    	var $visible    = true;/*Un champ peut etre invisible
    								- pour permettre des tests
    								- car rempli automatiquement et pour le design */
    	function row( ){
     
    	}
    	function test( ){
     
    	}
    }
     
     
    class formabs{
    	var $mode       = CONSULT;
    	var $table      = "";
    	var $SQL        = "";
    	var $primaryKey = array();//Key columns
    	var $protected  = array();//s'afficheront en consultation
    	var $automatique= array();//
    	var $numfields;
     
    	var $rows       = array();
    	var $ErrMsg 	= "";
     
    	var $traduction = array();
     
     
    	function formabs($SQL ){
    		//abstract 		
    	}
    	function mode($mode ){
    		$this->mode = $mode;
    	}
    	function protect($field ){
    		$this->protected[] = $field;
    	}
    	function primary($field ){
    		$this->primaryKey = $field;
    	}
     
    	[b]function traduction($dico ){
    		$this->traduction = $dico;
    		foreach ($this->rows as &$row) {
    			if (isset($this->traduction[$row->fieldName]) && $this->traduction[$row->fieldName] != "" ){
     
    				$row->label = $this->traduction[$row->fieldName];
    			}else{
    				$row->label = $row->fieldName;
    			}	
    		}
    	}[/b]
    	function getValue($field){
    		$rtn = 0;
    		for ($i=1;$i< $this->numfields; $i++){
    			if ($this->rows[$i]->fieldName == $field ) {
    				$rtn = $this->rows[$i]->fieldValue;
    			}else{
    				$rtn = 0;
    			}
    		}
    		return $rtn;
    	}//end getValue
    	function show(){
    		$count = $this->numfields;
     
    		$form = "<form method=POST action=".$_SERVER['PHP_SELF']."?mode=".$this->mode."> ";
    		$form .= "<table width=500 cellSpacing=0 cellPadding=0><TBODY>";
    		$i = 0;
    		foreach ($this->rows as $row) {
       			if ($row->visible){
     
    	   			//libellé
    	   			$i++;
    	   			$form .= "<tr class=data".(($i % 2) + 1) ."><td>".$row->label."</td>";
    	   			//icone
    			    $form .= "<td width=16>";
    			    if ( $row->fieldErrMsg != "" ) $form .= "<img src='../Img/b_drop.png'>";
    			    $form .= "</td>";
    			    //champ
    		    	$form .= "<td>";
    		    	$form .= $row->fieldValue;
    		    	$form .= "</td><td>&nbsp;</td></tr>";
    	   		}
    		}
     
     
    		/*for ($i=1; $i< $this->numfields ;$i++){
    			
    		    if ($this->mode && !in_array ($this->rows[$i]->fieldName, $this->protected) &&  $this->rows[$i]->fieldName != $this->primaryKey){
    			    switch($this->rows[$i]->fieldType){
    					case  'text':
    						$form .= "<TEXTAREA name='".$this->rows[$i]->fieldName."' rows=4 cols=40>".nl2br($this->rows[$i]->fieldValue)."</TEXTAREA>";
    						break;   
    				    default:
    				    	$form .= "<input type=text name='".$this->rows[$i]->fieldName."' value='".$this->rows[$i]->fieldValue."'>";
    				    	break;
    				    
    				}
    			}else{//consult
    				if ($this->rows[$i]->fieldName == $this->primaryKey){
    					 $form .= "<input name=".$this->rows[$i]->fieldName." type=hidden value=".$this->rows[$i]->fieldValue.">"; 
    					if ( ! $this->rows[$i]->fieldValue ) $form .= " automatique "; 
    				}
    				$form .= $this->rows[$i]->fieldValue;
    			}
    		        
    		    
    		}*/
     
    		$form .= "<TBODY></table>";
    		if ( $this->mode == MODIFY || $this->mode == ADD ){
    			 $form .= " <table width=100%><tr><td>";
    			 /*$form .= "<input name=fieldName type=hidden value=".serialize($this->fieldName).">";
    			 $form .= "<input name=fieldLen type=hidden value=".serialize($this->fieldLen).">";
    			 $form .= "<input name=fieldType type=hidden value=".serialize($this->fieldType).">";*/
    			 if ( $this->ErrMsg ) $form .= "<marquee>".$this->ErrMsg."</marquee>" ;
    			 $form .= "</td><td width=86 height=29><input type=image  src='../Img/bval.gif'></td></tr></table>";
    		}
    		if ( $this->ErrMsg ) $form .= $this->ErrMsg ;
    		$form .= "</form>";
    		return $form;
    	}// end show
    	function post( $post ){
    		$i = 1;
    		foreach ($this->fieldName as $valeurvar) {
    			$this->fieldValue[$i] = $post[$valeurvar];
    			$i++;
    		}
    	}//end post
    	function test( ){
    		$test = true;
    		for ($i=1;$i< $this->numfields ; $i++){
    				$this->fieldErrMsg[$i] = eval ($this->test[$i]);
    				if ( $this->fieldErrMsg[$i] != "" ) $test = false;
    		}
    		return $test;
    	}//end test
    	function commit( $obj_conn ){
    		$insert = "";
    		$values = "";
    		$update = "";
    		$virgule= "";
    		for ($i=1;$i< $this->numfields ; $i++){
    			if ( !in_array ($this->fieldName[$i], $this->protected)&&  $this->fieldName[$i] != $this->primaryKey){
     
    				switch($this->fieldType[$i]){
    					case 'int':
    						if ($this->fieldValue[$i]){
    							$insert .= $virgule.$this->fieldName[$i];
    							$values .= $virgule.$this->fieldValue[$i];
    						}
    						break;
    					case 'datetime':
    						if ($this->fieldValue[$i]){
    							$insert .= $virgule.$this->fieldName[$i];
    							//$values .= $virgule.$this->fieldValue[$i];
    							$values .= $virgule."'".date ("Y-m-j")."'";
    						}
    						break;
    					default:
    						if ($this->fieldValue[$i]){
    							$insert .= $virgule.$this->fieldName[$i];
    							$values .= $virgule."'".quote($this->fieldValue[$i])."'";
    						}
    						break;
    				}//end switch
    				$update .= "";
    				$virgule = " , ";
    			}//end if
    		}//next i
     
    		$primaryKeyValue = $obj_conn->nextPrimary( $this->primaryKey , $this->table );
     
     
     
    		if ($this->mode - 1){//insert
    			$SQL = "insert into ".$this->table." ( ".$insert." ) values ( ".$values." )";
    		}else{//update
    			$SQL = "update ".$this->table." set ".$update." where ".$this->primaryKey." = ".getValue($this->primaryKey);
    		}
    		echo $SQL;
     
    		$obj_conn->sql_exec($SQL);
    		$this->mode = CONSULT;
    		$this->ErrMsg = "<font color=green><b>Trackit Enregistré!</b></font>";
    	}//end commit
    }//end class
     
     
     
     
    $message = "";
    function error( $field_msg ){
    	global ${$field_msg};
    	global $message;
    	if ( isset(${$field_msg}) && ${$field_msg} != "" ){
    		echo "<img src=\"b_drop.png\" alt=\"".${$field_msg}."\">";
    		$message .= ${$field_msg}."\t";
    		}
    }
     
    function champ( $field , $attribut ){
    	global ${$field};
    	$field_msg = $field."_msg";
    	global ${$field_msg};
    	$value = "";
    	$class = "";
    	if ( isset(${$field_msg}) && ${$field_msg} != "" ){
    		$class ="class=\"incorrecte\" ";
    	}
    	else{
    		if( isset(${$field}) && ${$field} != "")	$value =" value=\"".${$field}."\"";		
    	}
    		echo "<input name=\"".$field."\" ".$class.$value.$attribut.">";
    }
     
     
     
    	//error("login_msg") ;
    	//champ("login", "type=\"text\" maxlength=\"20\" ");
     
     
    ?>
    *par default une variable est public... normalement c'est pas ca.
    *j'essaye aussi un passage par référence (&) mais ca me met un message d'erreur. EXPcting T_VAR...
    qqn a une idée?
    Merci d'avance

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    882
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 882
    Par défaut
    la partie en gras est celle ci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function traduction($dico ){
          $this->traduction = $dico;
          foreach ($this->rows as &$row) {
             if (isset($this->traduction[$row->fieldName]) && $this->traduction[$row->fieldName] != "" ){
     
                $row->label = $this->traduction[$row->fieldName];
             }else{
                $row->label = $row->fieldName;
             }   
          }
       }
    mais c'est tout ce que j'ai compris

  3. #3
    Membre expérimenté
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 208
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    foreach ($this->rows as &$row) {
             if (isset($this->traduction[$row->fieldName]) && $this->traduction[$row->fieldName] != "" ){
     
                $row->label = $this->traduction[$row->fieldName];
             }else{
                $row->label = $row->fieldName;
             }
    la structure foreach réalise un passage par valeur.
    autrement dit $row est detruite a la fin du bloc. le & n'y changera rien.
    Remplacez cette structure par un un for plus classique... 8)

    EDIT: <<la partie en gras est celle ci>> héhé, j'ai déviné

  4. #4
    Membre chevronné Avatar de XtofRoland
    Profil pro
    Inscrit en
    Août 2005
    Messages
    357
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2005
    Messages : 357
    Par défaut
    Merci,
    je remet l'ancien code alors ;-)

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

Discussions similaires

  1. [Performance]Accès JDOM/Attributs de classe
    Par leminipouce dans le forum Langage
    Réponses: 3
    Dernier message: 19/10/2006, 13h30
  2. Réponses: 2
    Dernier message: 24/08/2006, 17h48
  3. Réponses: 3
    Dernier message: 08/12/2005, 14h41
  4. [css]problème d'attribution de classe dans deux listes
    Par Mitaka dans le forum Mise en page CSS
    Réponses: 9
    Dernier message: 24/11/2005, 18h05
  5. Réponses: 9
    Dernier message: 02/09/2005, 15h44

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