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 :

Call to a member function on a non-object


Sujet :

PHP & Base de données

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Mai 2013
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Mai 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Call to a member function on a non-object
    Bonsoir tout le monde,

    Voila une capture du mon probléme:
    Nom : 7T11Hzy.png
Affichages : 59
Taille : 103,7 Ko

    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
    <?php
     
    class Panier extends CI_Controller { // Our Cart class extends the Controller class
     
    	function __Panier()
    	{
    		parent::__Panier(); // We define the the Controller class is the parent.	
    		$this->load->model('cart_model'); // Load our cart model for our entire class
    	}
     
    	function index()
     
    	{
    	    $this->db->select('*');
    	    $this->db->where('parent_id','0');
    		$data['categories']=$this->db->get('produit_categorie');
     
    		$this->db->select('*');
    	    $this->db->limit(3);
    		$data['newproduit']=$this->db->get('produit');
     
    		$data['produit'] = $this->cart_model->retrieve_products(); // récupérer les produits
     
    		$data['content'] = 'cart/products';
     
    		$this->load->view('header');
    		$this->load->view('left'); 
    		$this->load->view('panier_vue', $data); // affichage de la  page
    		$this->load->view('right');
    		$this->load->view('footer');
    	}
     
    	function add_cart_item(){
     
    		if($this->cart_model->validate_add_cart_item() == TRUE){
     
    			if($this->input->post('ajax') != '1'){
    				redirect('panier'); // If javascript is not enabled, reload the page with new data
    			}else{
    				echo 'true'; // If javascript is enabled, return true, so the cart gets updated
    			}
    		}
     
    	}
     
    	function update_cart(){
    		$this->cart_model->validate_update_cart();
    		redirect('panier/index');
    	}
     
    	function show_cart(){
    		$this->load->view('cart/cart2');
    	}
     
    	function empty_cart(){
    		$this->cart->destroy();
    		redirect('panier');
    	}
    }
     
    /* End of file cart.php */
    /* Location: ./application/controllers/cart.php */
    ?>

    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
    <?php 
     
    class Cart_model extends Model {
     
    	// Function to retrieve an array with all product information
    	function retrieve_products(){
    	     $this->db->select('*');        
    		$this->db->where('prix','');
    		$query = $this->db->get('produit',3);
    		return $query->result_array();
    	}
     
    	// Updated the shopping cart
    	function validate_update_cart(){
     
    		// Get the total number of items in cart
    		$total = $this->cart->total_items();  ///fonction prédefini dans CI
     
    		// Retrieve the posted information
    		$item = $this->input->post('rowid');
    	    $qty = $this->input->post('qty');
     
    	                                        // Cycle true all items and update them
    		for($i=0;$i < $total;$i++)
    		{
    			// Create an array with the products rowid's and quantities. 
    			$data = array(
                   'rowid' => $item[$i],
                   'qty'   => $qty[$i]
                );
     
                // Update the cart with the new information
    			$this->cart->update($data);
    		}
     
    	}
     
    	// Add an item to the cart
    	function validate_add_cart_item(){
     
    		$id = $this->input->post('produit_id'); // Assign posted product_id to $id
    		$cty = $this->input->post('quantite'); // Assign posted quantity to $cty
     
    		$this->db->where('id', $id); // Select where id matches the posted id
    		$query = $this->db->get('products', 1); // Select the products where a match is found and limit the query by 1
     
    		// Check if a row has been found
    		if($query->num_rows > 0){
     
    			foreach ($query->result() as $row)
    			{
    			    $data = array(
                   		'id'      => $id,
                   		'qty'     => $cty,
                   		'prix'   => $row->prix,
                   		'nom'    => $row->titre
                	);
     
    				$this->cart->insert($data); 
     
    				return TRUE;
    			}
     
    		// Nothing found! Return FALSE!	
    		}else{
    			return FALSE;
    		}
    	}
     
    	// Needed?
    	//function cart_content(){
    	//	return $this->cart->total();
    	//}
     
    }
     
     
    /* End of file cart_model.php */
    /* Location: ./application/models/cart_model.php */
    Merci Bien pour votre aide

  2. #2
    Membre confirmé Avatar de humitake
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2010
    Messages
    399
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2010
    Messages : 399
    Points : 578
    Points
    578
    Par défaut
    Bonjour,

    Ou est-ce que tu bloque ?
    Le message d'erreur est pourtant on ne peux plus clair, tu n'as pas initialiser ton objet.
    Ligne 22 :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $data['produit'] = $this->cart_model->retrieve_products(); // récupérer les produits
    //$this->cart_model n'a surement pas été initialiser d'où ton erreur :
    //Call to a member function retrieve_products() on a non object

  3. #3
    Nouveau Candidat au Club
    Inscrit en
    Mai 2013
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Mai 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Merci pour votre repense...

Discussions similaires

  1. [Joomla!] Erreur Call to a member function on a non-object
    Par tchaw dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 27/01/2010, 21h53
  2. [PHP 5.2] Problème : Call to a member function on a non-object
    Par Docteur_Hareng dans le forum Langage
    Réponses: 4
    Dernier message: 10/07/2009, 10h50
  3. Fatal error: Call to a member function on a non-object
    Par alemat13 dans le forum Langage
    Réponses: 6
    Dernier message: 31/12/2007, 17h22
  4. [POO] Call to a member function on a non-object
    Par Roromix dans le forum Langage
    Réponses: 3
    Dernier message: 25/04/2007, 14h40
  5. [phpToPDF] "Call to a member function on a non-object"
    Par pikatshu dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 16/04/2007, 18h47

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