Advertisement
Guest User

Untitled

a guest
May 8th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2.  
  3. class User extends Member {
  4. private static $db = array(
  5. "FirstName" => "Text",
  6. "Age" => "Int",
  7. "Address" => "Text"
  8. );
  9.  
  10. public static $has_one = array(
  11. 'Profile' => 'Profile'
  12. );
  13.  
  14.  
  15. public function onBeforeWrite()
  16. {
  17. parent::onBeforeWrite();
  18. if (! $this->Profile()->exists()) {
  19.  
  20. $profile = new Profile();
  21. $profile->User = $this->ID;
  22. $profile->write();
  23.  
  24. $this->ProfileID = $profile->ID;
  25. $this->update();
  26. }
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. <?php
  34.  
  35. class Profile extends DataObject {
  36.  
  37. public static $has_one = array(
  38. 'User' => 'User'
  39. );
  40.  
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. public function addNew() {
  50.  
  51. $NewUser = new User();
  52. $NewUser -> FirstName = "Jay Smith";
  53. $NewUser->write();
  54.  
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement