Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User extends Member {
- private static $db = array(
- "FirstName" => "Text",
- "Age" => "Int",
- "Address" => "Text"
- );
- public static $has_one = array(
- 'Profile' => 'Profile'
- );
- public function onBeforeWrite()
- {
- parent::onBeforeWrite();
- if ($this->Profile()->exists()) {
- $profile = new Profile();
- $profile->User = $this;
- $profile->write();
- }
- }
- <?php
- class Profile extends DataObject {
- public static $has_one = array(
- 'User' => 'User'
- );
- function getCMSFields() {
- $fields = new FieldList(new TabSet('Root'));
- return $fields;
- }
- }
- public function addNew() {
- $NewUser = new User();
- $NewUser -> FirstName = "User First Name";
- $NewUser->write();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement