CodeIgniter Forums
Codeigniter and DMZ` - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Codeigniter and DMZ` (/showthread.php?tid=23842)



Codeigniter and DMZ` - El Forum - 10-23-2009

[eluser]The Mask[/eluser]
Hi,
Can anyone please advise the recommended method for loading models using Datamapper?

Should I still be using the Codeigniter loader and then reference my models as:
$this->load->model( 'Foo' );
$this->Foo->bar();
or do I now need to use the following as in the documentation:
$foo = new Foo();
$foo->bar();

Thanks


Codeigniter and DMZ` - El Forum - 10-23-2009

[eluser]BrianDHall[/eluser]
You should use the latter form, for many reasons, but most specifically and simply the latter method allows you to have more than one Foo - and you'll often find you need such functionality when you least expect it.

Code:
$user = new User();
$user->get_where('username', 'shuckyducky');
$user->sig_line = 'Shucky!';
$user->save();

if ($command == 'delete')
{
$user->delete();
}

Also it is a lot less code to right to avoid use of $this->User - you could just have $user or even just $u.