[eluser]Unknown[/eluser]
Hello,
I have a error, and i don't find any solution (i'm newbies).
this is the code of my controler :
Code:
<?php
class Messages extends Controller {
function Messages(){
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('Messages_model','message', true);
$this->output->enable_profiler(true);
}
... some code
function valid_add(){ #validation du formulaire de saisie
if ($_POST['site_id']!=0): //Si on écrit un message depuis la liste des sites
$this->message->insert($_POST['site_id']); <-- WORKS
redirect('sites');
else: //on viens de la gestion des messages, on ecrit un msg a tous lessites existants
$sites = $this->db->get('sites');
foreach($sites->result() as $site):
$this->message->insert($_POST['site_id']); <-- ERROR
endforeach;
//redirect('messages');
endif;
}
... some code
}
?>
my controler look like :
Code:
<?php
class Messages_model extends Model {
function Messages_model(){
parent::Model();
$this->load->helper('date');
}
function insert($id){
$datestring = "%Y-%m-%d %h:%i:%s";
$this->date = mdate($datestring, time());
$this->titre = $_POST['titre'];
$this->message = $_POST['texte'];
$this->site_id = $id;
$this->db->insert('messages', $this);
}
some code ...
}
?>
with this code, i have the folowing error :
Code:
Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\SITE\system\application\controllers\messages.php on line 43
if i don't use
foreach in my function it works.
Where is the error (don't say : a line 43 :lol: )
thank's, sorry for my english, i'm french.