[eluser]TheFuzzy0ne[/eluser]
OK. This was my update method in my model:
Code:
function _update($forum)
{
$this->db->where('id', $forum['id']);
unset($forum['id']);
return $this->db->update($this->table, $forum);
}
Fairly primitive really.
Here's the same method, only pimped:
Code:
function _update($forum)
{
$this->db->where('id', $forum['id']);
unset($forum['id']);
foreach ($forum as $key => $val)
{
if (preg_match('/^([a-z0-9_]+)\s?\+\s?\d+$/i', $val, $matches))
{
if (isset($this->fields[$matches[1]]))
{
$this->db->set($key, $val, FALSE);
unset($forum[$key]);
}
}
}
return $this->db->update($this->table, $forum);
}
All of my models contain a list of fields, so I loop through the array, looking for a pattern that matches /^([a-z0-9_]+)\s?\+\s?\d+$/i, then I check the field name, to ensure it's actually a field name, and then I do a set manually, and remove it from the array. Ideally, I don't want any other values to be inserted without first being escaped. Any further suggestions for improvement are welcomed.
Perhaps I should just call set on each row, since I'm looping through the array anyway?
Thanks for your comments, Dam1an. Stop double-posting - it's naughty.