Skip to content

Instantly share code, notes, and snippets.

@rATRIJS
Created February 7, 2012 19:43
Show Gist options
  • Save rATRIJS/1761471 to your computer and use it in GitHub Desktop.
Save rATRIJS/1761471 to your computer and use it in GitHub Desktop.
Random OOP example
<?php
class DB {
public static function insert($table, $properties) {
// izveido SQL un izpildi
}
}
class Model {
public function __construct($properties) {
foreach($properties as $property_name => $property_value)
if(property_exists($this, $property_name)) $this->$property_name = $property_value;
}
public function create() {
$properties = array();
foreach($this as $name => $value)
$properties[$name] = $value;
$this->id = DB::insert(static::TABLE_NAME, $properties);
}
}
class User extends Model {
const TABLE_NAME = 'users';
public $id;
public $name;
public $email;
}
$user = new User(array(
'name' => 'Name',
'email' => 'example@example.com'
));
$user->create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment