-
-
Save rintaun/2370039 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 { | |
/** | |
* Load a row from the database | |
* | |
* 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. | |
* | |
* @param int $id ID for the row you wish to load | |
* @return Model | |
*/ | |
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