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

MkFramework Discussion :

Trying to get property of non-object


Sujet :

MkFramework

  1. #1
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Mars 2013
    Messages
    201
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mars 2013
    Messages : 201
    Points : 75
    Points
    75
    Par défaut Trying to get property of non-object
    Encore une erreur incompréhensible.

    Je n'arrive pas à afficher la liste des classes du prof connecté.

    Dans le model classes j'ai ajouter function findClassesById($user_id) ligne 19
    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
    <?php
    class model_classes extends abstract_model{
     
    	protected $sClassRow='row_classes';
     
    	protected $sTable='classes';
    	protected $sConfig='mysq';
     
    	protected $tId=array('id');
     
    	public static function getInstance(){
    		return self::_getInstance(__CLASS__);
    	}
     
    	public function findById($uId){
    		return $this->findOne('SELECT * FROM '.$this->sTable.' WHERE id=?',$uId );
    	}
     
    	public function findClassesById($user_id){
    		return $this->findMany('SELECT '.$this->sTable.'.nom, '.$this->sTable.'.atelier_id, '.$this->sTable.'.session_id 
    		 FROM '.$this->sTable.', classesProfs 
    			WHERE classes.id=classesProfs.classe_id
    			AND classesProfs.user_id=?',$user_id);
    	}
    	public function findBySession_id($session_id){
    		return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE session_id=? ORDER BY nom ASC',$session_id);
    	}	
    	public function findAll(){
    		return $this->findMany('SELECT * FROM '.$this->sTable);
    	}						
     
    	public function findAllByAtelier($atelier_id){
    		return $this->findMany('SELECT * FROM '.$this->sTable. 'WHERE atelier_id=?',$atelier_id);
    	}
     
     
    	public function getSelect(){
    		$tab=$this->findAll();
    		$tSelect=array();
    		if($tab){
    		foreach($tab as $oRow){
    			$tSelect[ $oRow->id ]=$oRow->nom;
    		}
    		}
    		return $tSelect;
    	}
     
    	public function getSelectByAtelier(){
    		$tab=$this->findAll();
    		$tSelect=array();
    		if($tab){
    		foreach($tab as $oRow){
    			$tSelect[ $oRow->id ]=$oRow->nom;
    		}
    		}
    		return $tSelect;
    	}
     
    }
     
    class row_classes extends abstract_row{
     
    	protected $sClassModel='model_classes';
     
    	//jointure classes.atelier_id->ateliers.nom
    	public function findAtelierClasse(){
       return model_ateliers::getInstance()->findById($this->atelier_id);
       //on retourne l'enregistrement "atelier" recupéré via la clé étrangère "atelier_id"
    	}
     
     
    	/*exemple test validation*/
    	private function getCheck(){
    		$oPluginValid=new plugin_valid($this->getTab());
    		/* renseigner vos check ici
    		$oPluginValid->isEqual('champ','valeurB');
    		$oPluginValid->isNotEqual('champ','valeurB');
    		$oPluginValid->isUpperThan('champ','valeurB');
    		$oPluginValid->isUpperOrEqualThan('champ','valeurB');
    		$oPluginValid->isLowerThan('champ','valeurB');
    		$oPluginValid->isLowerOrEqualThan('champ','valeurB');
    		$oPluginValid->isEmpty('champ');
    		$oPluginValid->isNotEmpty('champ');
    		$oPluginValid->isEmailValid('champ');
    		$oPluginValid->matchExpression('champ','/[0-9]/');
    		$oPluginValid->notMatchExpression('champ','/[a-zA-Z]/');
    		*/
     
    		return $oPluginValid;
    	}
     
    public function isValid(){
    		return $this->getCheck()->isValid();
    	}
    	public function getListError(){
    		return $this->getCheck()->getListError();
    	}
    	public function save(){
    		if(!$this->isValid()){
    			return false;
    		}
    		parent::save();
    		return true;
    	}
     
    }
    Dans la méthode show() j'ai
    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
    <?php 
    class module_classesProf extends abstract_module{
     
    	public function before(){
    		$this->oLayout=new _layout('template1');
     
    		$this->oLayout->addModule('menu','menu::left');
    	}
     
     
    	public function _index(){
    	    //on considere que la page par defaut est la page de listage
    	    $this->_list();
    	}
     
    	public function _list(){
     
    		$tClasses=model_classes::getInstance()->findAll();
     
    		$oView=new _view('classesProf::list');
    		$oView->tClasses=$tClasses;
     
    				$oView->tJoinmodel_ateliers=model_ateliers::getInstance()->getSelect();		$oView->tJoinmodel_sessions=model_sessions::getInstance()->getSelect();
     
    		$this->oLayout->add('main',$oView);
    	}
     
     
    	public function _new(){
    		$tMessage=$this->save();
     
    		$oClasses=new row_classes;
     
    		$oView=new _view('classesProf::new');
    		$oView->oClasses=$oClasses;
     
    				$oView->tJoinmodel_ateliers=model_ateliers::getInstance()->getSelect();		$oView->tJoinmodel_sessions=model_sessions::getInstance()->getSelect();
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
    		$this->oLayout->add('main',$oView);
    	}
     
     
    	public function _edit(){
    		$tMessage=$this->save();
     
    		$oClasses=model_classes::getInstance()->findById( _root::getParam('id') );
     
    		$oView=new _view('classesProf::edit');
    		$oView->oClasses=$oClasses;
    		$oView->tId=model_classes::getInstance()->getIdTab();
     
    				$oView->tJoinmodel_ateliers=model_ateliers::getInstance()->getSelect();		$oView->tJoinmodel_sessions=model_sessions::getInstance()->getSelect();
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
    		$this->oLayout->add('main',$oView);
    	}
     
    	public function _show(){
    		$oClasses=model_classes::getInstance()->findClassesById( _root::getAuth()->getAccount()->id) ;
     
    		$oView=new _view('classesProf::show');
    		$oView->oClasses=$oClasses;
     
    		$oView->tJoinmodel_ateliers=model_ateliers::getInstance()->getSelect();		
    		$oView->tJoinmodel_sessions=model_sessions::getInstance()->getSelect();
    		$this->oLayout->add('main',$oView);
    	}
     
    	public function _delete(){
    		$tMessage=$this->delete();
     
    		$oClasses=model_classes::getInstance()->findById( _root::getParam('id') );
     
    		$oView=new _view('classesProf::delete');
    		$oView->oClasses=$oClasses;
     
    				$oView->tJoinmodel_ateliers=model_ateliers::getInstance()->getSelect();		$oView->tJoinmodel_sessions=model_sessions::getInstance()->getSelect();
     
    		$oPluginXsrf=new plugin_xsrf();
    		$oView->token=$oPluginXsrf->getToken();
    		$oView->tMessage=$tMessage;
     
    		$this->oLayout->add('main',$oView);
    	}
     
    	public function save(){
    		if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas
    			return null;
    		}
     
    		$oPluginXsrf=new plugin_xsrf();
    		if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide
    			return array('token'=>$oPluginXsrf->getMessage() );
    		}
     
    		$iId=_root::getParam('id',null);
    		if($iId==null){
    			$oClasses=new row_classes;	
    		}else{
    			$oClasses=model_classes::getInstance()->findById( _root::getParam('id',null) );
    		}
     
    		$tId=model_classes::getInstance()->getIdTab();
    		$tColumn=model_classes::getInstance()->getListColumn();
    		foreach($tColumn as $sColumn){
    			 if(isset($_FILES[$sColumn]) and $_FILES[$sColumn]['size'] > 0){
    				$sNewFileName='data/upload/'.$sColumn.'_'.date('Ymdhis');
     
    				$oPluginUpload=new plugin_upload($_FILES[$sColumn]);
    				$oPluginUpload->saveAs($sNewFileName);
    				$oClasses->$sColumn=$oPluginUpload->getPath();
    				continue;	
    			}else  if( _root::getParam($sColumn,null) ==null ){ 
    				continue;
    			}else if( in_array($sColumn,$tId)){
    				 continue;
    			}
     
    			$oClasses->$sColumn=_root::getParam($sColumn,null) ;
    		}
     
    		if($oClasses->isValid()){
     
    			$oClasses->save();
    			//une fois enregistre on redirige (vers la page liste)
    			_root::redirect('classesProf::list');
    		}else{
    			return $oClasses->getListError();
    		}
     
    	}
     
    	public function delete(){
    		if(!_root::getRequest()->isPost() ){ //si ce n'est pas une requete POST on ne soumet pas
    			return null;
    		}
     
    		$oPluginXsrf=new plugin_xsrf();
    		if(!$oPluginXsrf->checkToken( _root::getParam('token') ) ){ //on verifie que le token est valide
    			return array('token'=>$oPluginXsrf->getMessage() );
    		}
     
    		$oClasses=model_classes::getInstance()->findById( _root::getParam('id',null) );
     
    		$oClasses->delete();
    		//une fois enregistre on redirige (vers la page liste)
    		_root::redirect('classesProf::list');
     
    	}
     
    	public function after(){
    		$this->oLayout->show();
    	}
     
     
    }
     
    /*variables
    #select		$oView->tJoinclasses=classes::getInstance()->getSelect();#fin_select
    #uploadsave if(isset($_FILES[$sColumn]) and $_FILES[$sColumn]['size'] > 0){
    				$sNewFileName='data/upload/'.$sColumn.'_'.date('Ymdhis');
    
    				$oPluginUpload=new plugin_upload($_FILES[$sColumn]);
    				$oPluginUpload->saveAs($sNewFileName);
    				$oClasses->$sColumn=$oPluginUpload->getPath();
    				continue;	
    			}else #fin_uploadsave
    variables*/
    $oClasses me retourne bien un tableau avec le nom, session_id et atelier_id des classes.
    Et dans la vue show j'ai bien fait attention de respecter la syntaxe cette fois.


    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
    <table class="tb_show">
     
    	<tr>
    		<th>nom</th>
    		<td><?php echo $this->oClasses->nom ?></td>
    	</tr>
     
    	<tr>
    		<th>atelier</th>
    		<td><?php echo $this->tJoinmodel_ateliers[$this->oClasses->atelier_id]?></td>
    	</tr>
     
    	<tr>
    		<th>session</th>
    		<td><?php echo $this->tJoinmodel_sessions[$this->oClasses->session_id]?></td>
    	</tr>
     
    </table>
    <p> <a href="<?php echo $this->getLink('classesProf::list')?>">Retour</a></p>

  2. #2
    Rédacteur
    Avatar de imikado
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    5 239
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2006
    Messages : 5 239
    Points : 19 100
    Points
    19 100
    Billets dans le blog
    17
    Par défaut
    Votre methode getClasseById retournant un tableau, renommer la variable $tClasse plutot que $oClasse

    T pour tableau, o pour objet

    Ensuite dans votre vue, vous devrierz avoir un foreach pour boucler sur ce tableau:
    Ajoutez au dessus du tableau html
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <?php foreach($this->tClasse as $oClasse):?>
    Dans le tableau remplacez $this->oClasse par $oClasse

    Et en dessous du tableau, fermez le foreach
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <?php endforeach; ?>
    Framework php sécurisé et simple à prendre en main avec générateur web http://mkframework.com/ (hebergé sur developpez.com)
    Mes cours/tutoriaux

  3. #3
    Membre régulier
    Homme Profil pro
    Enseignant
    Inscrit en
    Mars 2013
    Messages
    201
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mars 2013
    Messages : 201
    Points : 75
    Points
    75
    Par défaut
    Bonjour,

    C'est bon ça marche j'ai trouvé mon erreur. La nuit à porté conseil.

    Je vous ai fait cherché pour rien désolé

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

Discussions similaires

  1. [MySQL] Erreur de type : "Trying to get property of non-object in"
    Par Prisss dans le forum PHP & Base de données
    Réponses: 25
    Dernier message: 16/12/2010, 07h02
  2. [Joomla!] [Adsmanager] Notice: Trying to get property of non-object in C:\Program Files\EasyPHP
    Par ninobrown dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 5
    Dernier message: 13/04/2009, 21h13
  3. Réponses: 3
    Dernier message: 08/02/2008, 20h02
  4. Réponses: 11
    Dernier message: 28/08/2007, 12h06
  5. [POO] Erreur Trying to get property of non-object
    Par Niouts dans le forum Langage
    Réponses: 14
    Dernier message: 13/09/2006, 10h09

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