那么,我继续前进,就像我说的那样。弗兰克是对的,这不是太难。下面是代码柜面任何人想用它在支持AR风格DB调用像笨或MicroMVC一个MVC:
/*
* Multi-table user voting model
*/
class votes extends model {
public static $table = 'votes';
function cast($user_id = NULL, $item_id = NULL, $type = NULL, $vote = TRUE) {
$where = array(
'user_id' => $user_id,
'item_id' => $item_id,
'type' => $type
);
//Try to fetch this row
$row = $this->db->get_where(self::$table, $where);
//Look for an existing vote row
if($row && ! empty($row[0])) {
//Fetch row
$row = $row[0];
//If they already voted this way... then we're done!
if($row->vote == $vote) {
return;
}
//Else update the row to the new vote
$row->vote = $vote;
$row->date = convert_time(time());
$this->db->update(self::$table, $row, array('id' => $row->id));
return;
}
//Else create a new vote for this item
$row = array(
'user_id' => $user_id,
'item_id' => $item_id,
'type' => $type,
'date' => convert_time(time()),
'vote' => $vote,
);
$this->db->insert(self::$table, $row);
}
}
这是其中的一件事情是很简单的,和特定应用足够了,它可能是更容易自己构建它。除非您使用流行的框架或平台,在这种情况下,可能存在一个模块,但您需要指定您正在使用的框架/平台 – 2009-09-02 21:27:49