那麼,我繼續前進,就像我說的那樣。弗蘭克是對的,這不是太難。下面是代碼櫃面任何人想用它在支持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