Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created April 12, 2012 18:50
Show Gist options
  • Save sycobuny/2370033 to your computer and use it in GitHub Desktop.
Save sycobuny/2370033 to your computer and use it in GitHub Desktop.
<?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