<?Php
class User extends CI_Model
{
private static $user = null;
private $Username;
private $Balance;
private $TransactoinIndex;
private function __construct($strUsername)
{
parent::__construct();
$this->Username = $strUsername;
// 从数据库加载此用户的资料
$this->Balance = 100.00;
$this->TransactionIndex = 1;
}
public static function Login($strUsername, $strPassword)
{
// 查询数据库,如果用户登陆成功,则创建唯一实例对象
if ($strUsername == 'Lory' && $strPassword == '123456')
{
CUser::$user = new CUser('Lory');
}
return CUser::$user;
}
public static function GetUser()
{
return CUser::$user;
}
public function PrintInfo()
{
echo "Username: {$this->Username}<br>";
echo "Balance: {$this->Balance}<br>";
echo "TransactionIndex: {$this->TransactionIndex}<br>";
}
}
?>