[eluser]xinq88[/eluser]
Hello everyone,
I'm new to codeigniter, but already have a pretty stupid question :down:.
So the following scenario happened: I have some class which depends on an other class.
So far I've written the following code:
Code:
/* this represents the way i use it in the present */
include_once('uur.php');
/**/
class UserInterface extends Controller {
var $uur;
var $data;
var $partials;
function UserInterface()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
/* this represents the way i use it in the present */
$this->uur = new Uur();
$this->content = $this->listUren();
$this->content = $this->addUren();
}
function addUren()
{
// Set de title
$this->data['title'] = 'uren toevoegen';
// Set de view
$this->partials = array('content'=>'uren_toevoegen');
// Roep de functie toevoegen aan van de class Uur
$this->uur->toevoegen('klanttest', '2008-08-05', '2');
// Laad alle gegevens in de template 'main'
$this->template->load('main', $this->partials, $this->data);
}
}
Code:
class Uur extends Controller {
var $data;
function index()
{
$this->load->database(); // Doesn't work
}
function toevoegen($klant, $datum, $tijd)
{
$data = array(
'klant' => $klant,
'datum' => $datum,
'tijd' => $tijd
);
//$this->load->database();
$this->db->insert('uren', $data);
}
function overzicht()
{
//Laad het database model, zodat database functies gebruikt kunnen worden
//$this->load->database();
return $this->db->get('uren');
}
}
I don't think this is the 'codeigniter way' to include a class, because in this situation I can't seem to use the database helper etc. Also the constructor of the class Uur is not called when the following method is called: $this->uur = new Uur();
The output when I don't load the database helper in a specific function (like 'toevoegen') i get the following error while I have the database autoloaded:
Code:
Call to a member function get() on a non-object
I hope my poor English is understandable.
With kind regards,
Nick
(PS: I did google..)