BaseDBO.php 791 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class BaseDBO
  3. {
  4. public function GetId()
  5. {
  6. return $this->id;
  7. }
  8. public function __get($name)
  9. {
  10. if ($name == 'id')
  11. return $this->id;
  12. }
  13. public function Save()
  14. {
  15. global $entityManager;
  16. $entityManager->persist($this);
  17. $entityManager->flush();
  18. }
  19. public static function Find($id)
  20. {
  21. global $entityManager;
  22. return $entityManager->find(get_called_class(), $id);
  23. }
  24. public static function Delete($id)
  25. {
  26. global $entityManager;
  27. $user = $entityManager->getReference(get_called_class(), $id);
  28. $entityManager->remove($user);
  29. $entityManager->flush();
  30. echo "Элемент удален: $id";
  31. }
  32. }