Advertisement
Guest User

Untitled

a guest
May 8th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 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. $profile = new Profile();
  20. $profile->User = $this;
  21. $profile->write();
  22. }
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. <?php
  31.  
  32. class Profile extends DataObject {
  33.  
  34. public static $has_one = array(
  35. 'User' => 'User'
  36. );
  37.  
  38. function getCMSFields() {
  39. $fields = new FieldList(new TabSet('Root'));
  40. return $fields;
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. public function addNew() {
  51.  
  52. $NewUser = new User();
  53. $NewUser -> FirstName = "User First Name";
  54. $NewUser->write();
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement