Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created February 9, 2013 11:43
Show Gist options
  • Save coreymcmahon/4744983 to your computer and use it in GitHub Desktop.
Save coreymcmahon/4744983 to your computer and use it in GitHub Desktop.
Our User model, version 2.0. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 11
<?php
class User
{
public $id;
public $username;
public $firstname;
public $lastname;
public $email;
public function __construct($data = null)
{
if (is_array($data)) {
if (isset($data['id'])) $this->id = $data['id'];
$this->username = $data['username'];
$this->firstname = $data['firstname'];
$this->lastname = $data['lastname'];
$this->email = $data['email'];
}
}
public function getFullname()
{
echo $this->firstname . ' ' . $this->lastname;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment