• 数据对象创建
    • 示例:
    • 调用:

    数据对象创建

    mysqli组件没有自行封装数据对象,可通过继承EasySwoole工具类splBean自行创建一个数据对象.

    示例:

    1. <?php
    2. /**
    3. * Created by PhpStorm.
    4. * User: yf
    5. * Date: 2018/11/5
    6. * Time: 10:09 AM
    7. */
    8. namespace App\Model\User;
    9. use EasySwoole\Spl\SplBean;
    10. class UserBean extends SplBean
    11. {
    12. protected $id;
    13. protected $account;
    14. protected $password;
    15. protected $nickName;
    16. protected $openId;
    17. protected $addTime;
    18. protected $lastLoginTime;
    19. protected $balance;
    20. protected $mobile;
    21. /**
    22. * @return mixed
    23. */
    24. public function getId()
    25. {
    26. return $this->id;
    27. }
    28. /**
    29. * @param mixed $id
    30. */
    31. public function setId($id): void
    32. {
    33. $this->id = $id;
    34. }
    35. /**
    36. * @return mixed
    37. */
    38. public function getAccount()
    39. {
    40. return $this->account;
    41. }
    42. /**
    43. * @param mixed $account
    44. */
    45. public function setAccount($account): void
    46. {
    47. $this->account = $account;
    48. }
    49. /**
    50. * @return mixed
    51. */
    52. public function getAddTime()
    53. {
    54. return $this->addTime;
    55. }
    56. /**
    57. * @param mixed $addTime
    58. */
    59. public function setAddTime($addTime): void
    60. {
    61. $this->addTime = $addTime;
    62. }
    63. /**
    64. * @return mixed
    65. */
    66. public function getBalance()
    67. {
    68. return $this->balance;
    69. }
    70. /**
    71. * @param mixed $balance
    72. */
    73. public function setBalance($balance): void
    74. {
    75. $this->balance = $balance;
    76. }
    77. /**
    78. * @return mixed
    79. */
    80. public function getLastLoginTime()
    81. {
    82. return $this->lastLoginTime;
    83. }
    84. /**
    85. * @param mixed $lastLoginTime
    86. */
    87. public function setLastLoginTime($lastLoginTime): void
    88. {
    89. $this->lastLoginTime = $lastLoginTime;
    90. }
    91. /**
    92. * @return mixed
    93. */
    94. public function getMobile()
    95. {
    96. return $this->mobile;
    97. }
    98. /**
    99. * @param mixed $mobile
    100. */
    101. public function setMobile($mobile): void
    102. {
    103. $this->mobile = $mobile;
    104. }
    105. /**
    106. * @return mixed
    107. */
    108. public function getNickName()
    109. {
    110. return $this->nickName;
    111. }
    112. /**
    113. * @param mixed $nickName
    114. */
    115. public function setNickName($nickName): void
    116. {
    117. $this->nickName = $nickName;
    118. }
    119. /**
    120. * @return mixed
    121. */
    122. public function getOpenId()
    123. {
    124. return $this->openId;
    125. }
    126. /**
    127. * @param mixed $openId
    128. */
    129. public function setOpenId($openId): void
    130. {
    131. $this->openId = $openId;
    132. }
    133. /**
    134. * @return mixed
    135. */
    136. public function getPassword()
    137. {
    138. return $this->password;
    139. }
    140. /**
    141. * @param mixed $password
    142. */
    143. public function setPassword($password): void
    144. {
    145. $this->password = md5($password);
    146. }
    147. }

    调用:

    1. <?php
    2. $user = new UserBean(['account'=>'tioncico']);
    3. $user->setPassword(123456);
    4. $user->setMobile('15000011000');
    5. $account = $user->getAccount();
    6. $user_array = $user->toArray(null, UserBean::FILTER_NOT_NULL);//转为数组并过滤掉null值