Welcome Guest, Not a member yet? Register   Sign In
Load model with a constructer - possible?
#5

[eluser]Michael Wales[/eluser]
Definitely not enough coffee in me yet to wrap my head around this.

Here's the short and dirty of what I was trying to get at with the way CodeIgniter is currently setup - all Models are Singletons:

Code:
// Loads the correct file, instantiates the object
$this->load->model('user');
// Just returns the previously instantiated object
$this->load->model('user');

So - something like this, assuming the 2nd parameter is a constructor variable, isn't really possible:

Code:
$user = $this->load->model('user', 2);
$user->username = 'walesmd'; // Set a new username
$user2 = $this->load->model('user', 4);
$user2->username = 'dallard'; //
$user3 = new User(4);
$user3->username = 'djones';

// Can you guess what this line returns?
echo $user->username;
// Result:  dallard

/* This should work properly, but I think the loading of the model, then just ignoring that object completely is ugly as sin
*/
echo $user3->username;


Messages In This Thread
Load model with a constructer - possible? - by El Forum - 08-26-2008, 02:42 PM
Load model with a constructer - possible? - by El Forum - 08-27-2008, 01:58 PM
Load model with a constructer - possible? - by El Forum - 08-27-2008, 02:27 PM
Load model with a constructer - possible? - by El Forum - 08-27-2008, 03:08 PM
Load model with a constructer - possible? - by El Forum - 08-27-2008, 11:05 PM
Load model with a constructer - possible? - by El Forum - 08-28-2008, 08:08 AM
Load model with a constructer - possible? - by El Forum - 08-28-2008, 09:58 AM
Load model with a constructer - possible? - by El Forum - 08-28-2008, 12:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB