Welcome Guest, Not a member yet? Register   Sign In
Preferred model approach - instantiated or not?
#4

[eluser]BrianDHall[/eluser]
You might check out Datamapper Overzealous Extention over in Ignited Code forum - it works just this way but handles your least-enjoyed cases like getUsersByFirstName($fname):

Code:
$user = new User();
$user->get_where('first_name', $fname);

foreach ($user->all as $u)
{
$u->first_name = $u->first_name . 'jacobjingleheimerschmidt';
$u->save();
}

It allows you to avoid trying to differentiate between insert() or update() needs (just use save()), it has lots of cool magic functions to help you get the data you want cleanly and concisely in one line of code (usually), and to top it off it also handles relationships (being ORM, after all). It is built on CI's use of ActiveRecord so you can always call SQL directly when needed.

DMZ also has an array extention that is just friggin' cool, it allows you to do things like:

Code:
if ($_POST)
{
$user = new User();
$user->from_array($_POST, '', true);
// 'true' allows auto-save, saving you a call to ->save(); Or if you prefer:
$user->from_array($_POST)->save();
}

All of which you could just program yourself...but why bother?

Free, open source, easily extendable, it allows all the positives of your first noted way of handling things but allows even shorter syntax than the second mentioned way of doing things.

I heart DMZ.


Messages In This Thread
Preferred model approach - instantiated or not? - by El Forum - 11-03-2009, 07:18 PM
Preferred model approach - instantiated or not? - by El Forum - 11-03-2009, 07:45 PM
Preferred model approach - instantiated or not? - by El Forum - 11-03-2009, 09:13 PM
Preferred model approach - instantiated or not? - by El Forum - 11-03-2009, 09:57 PM
Preferred model approach - instantiated or not? - by El Forum - 11-03-2009, 10:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB