Created
April 12, 2012 18:50
-
-
Save sycobuny/2370033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model { | |
/* public Model->load(Integer) | |
* returns $this | |
* | |
* Pulls data from the database for a given model into the object. Note | |
* that this clears any state (modifications/etc.) that have been set | |
* on the object first, for any Model-controlled columns. | |
*/ | |
public function load($id) { | |
$table = $this->table(); | |
$query = "SELECT * FROM $table WHERE id = $1"; | |
$name = "_load_$table"; | |
$data = Database::prefetch($query, Array($id), $name); | |
$this->_set_all($data[0]); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment