Skip to content

Instantly share code, notes, and snippets.

@rintaun
Forked from sycobuny/model.php
Created April 12, 2012 18:51
Show Gist options
  • Save rintaun/2370039 to your computer and use it in GitHub Desktop.
Save rintaun/2370039 to your computer and use it in GitHub Desktop.
<?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