allserv | Bonsoir,
J'ai un petit problème avec CodeIgniter mais qui s'apparente à un problème général de POO.
Mon objet est déclaré dans une classe dont voici le code :
Code :
- <?php
- class Mdl_Contact extends Model {
- var $id = '';
- var $societe = '';
- var $secteur = '';
- var $nom = '';
- var $prenom = '';
- var $adresse = '';
- var $code_postal = '';
- var $tel = '';
- var $fax = '';
- var $port = '';
- var $email = '';
- var $societe_technique = '';
- var $nom_technique = '';
- var $prenom_technique = '';
- var $adresse_technique = '';
- var $code_postal_technique = '';
- var $tel_technique = '';
- var $fax_technique = '';
- var $email_technique = '';
-
- function Mdl_Contact()
- {
- // Call the Model constructor
- parent::Model();
-
-
- }
-
- function save() {
-
- $db_array = array(
- "id" => $this->id,
- "societe" => $this->societe,
- "secteur" => $this->secteur,
- "nom" => $this->nom,
- "prenom" => $this->prenom,
- "adresse" => $this->adresse,
- "code_postal" => $this->code_postal,
- "tel" => $this->tel,
- "fax" => $this->fax,
- "port" => $this->port,
- "email" => $this->email,
- "societe_technique" => $this->societe_technique,
- "nom_technique" => $this->nom_technique,
- "prenom_technique" => $this->prenom_technique,
- "adresse_technique" => $this->adresse_technique,
- "code_postal_technique" => $this->code_postal_technique,
- "tel_technique" => $this->tel_technique,
- "fax_technique" => $this->fax_technique,
- "email_technique" => $this->email_technique
-
- );
-
- // If mdl_contacts->contact_id was set in the controller, then we will update an existing record.
- if ($this->id) {
- $this->db->where("id", $this->id);
- $this->db->update("contacts", $db_array);
- }
- // If mdl_contacts->contact_id was not set in the controller, then we will insert a new record.
- else {
- $this->db->insert("contacts", $db_array);
- }
- }
-
-
- function toString(){
-
- $tmp = "<ul>";
-
- foreach(get_class_vars(get_class($this)) as $key=>$value) {
- if($key != "_parent_name" ) {
- $val = $this->$key;
- $tmp .= "<li>".$key." : ".$value."</li>";
- }
- }
- $tmp .= "</ul>";
- echo $tmp;
- }
- }
- ?>
|
Mon code qui créer l'instance de 'lobjet et le rempli est le suivant : Code :
- // Enregistrement dans la session
- $contact =& new Mdl_Contact();
- $contact->societe = $this->input->post('societe') ;
- $contact->secteur = $this->input->post('secteur') ;
- $contact->nom = $this->input->post('nom') ;
- $contact->prenom = $this->input->post('prenom') ;
- $contact->adresse = $this->input->post('adresse') ;
- $contact->code_postal = $this->input->post('code_postal') ;
- $contact->tel = $this->input->post('tel') ;
- $contact->fax = $this->input->post('fax') ;
- $contact->port = $this->input->post('port') ;
- $contact->email = $this->input->post('email') ;
- $contact->societe_technique = $this->input->post('societe_technique') ;
- $contact->secteur_technique = $this->input->post('secteur_technique') ;
- $contact->nom_technique = $this->input->post('nom_technique') ;
- $contact->prenom_technique = $this->input->post('prenom_technique') ;
- $contact->adresse_technique = $this->input->post('adresse_technique') ;
- $contact->code_postal_technique = $this->input->post('code_postal_technique') ;
- $contact->tel_technique = $this->input->post('tel_technique') ;
- $contact->fax_technique = $this->input->post('fax_technique') ;
- $contact->port_technique = $this->input->post('port_technique') ;
- $contact->email_technique = $this->input->post('email_technique');
- $contact->toString();
- echo "societe : form=".$this->input->post('secteur')." | objet=".$contact->secteur ;
|
Comme vous pouvez le constater j'appel la méthode toString() à la fin des affectations ainsi qu'un echo basique pour vérifier une donnée issue du formulaire et le contenu du contact.
Le problème réside dans le fait que la méthode toString() n'affiche aucune valeur issue du formulaire alors que lors du echo les deux affichages fonctionnent parfaitement ?
Citation :
id :
societe :
secteur :
nom :
prenom :
adresse :
code_postal :
tel :
fax :
port :
email :
societe_technique :
nom_technique :
prenom_technique :
adresse_technique :
code_postal_technique :
tel_technique :
fax_technique :
email_technique :
societe : form=qsc | objet=qsc
|
Merci d'avance pour votre aide.
Louis |