I use this in my set up and what it does it registers a USER and Creates the
PROFILE at the same time. I cleaned it out and left the parts you need to
accomplish the same thing.

function register()
      {
          if (!empty($this->data)) {
              if (isset($this->data['User']['password2']))
                  $this->data['User']['password2hashed'] =
$this->Auth->password($this->data['User']['password2']);

              $user = $this->User->save($this->data);
              // If the user was saved, Now we add this information to the
data and save the Profile.
              if (!empty($user)) {
                  // The ID of the newly created user has been set as
$this->User->id.
                  $this->data['User']['user_id'] = $this->User->id;
                        $this->User->Profile->save($this->data);
                  $this->redirect(array('controller' => 'users', 'action' =>
'index'));
              } else {
                  $this->Session->setFlash(__('The User could not be saved.
Please, try again.', true));
                  $this->data = null;
              }
          }
      }

And in the register form:
div class="users form">
<?php echo $form->create('User', array('action' => 'register'));?>
        <fieldset>
                <legend></legend>
        <?php
                echo $form->input('Profile.firstname');
                echo $form->input('Profile.lastname');
                
                echo $form->input('User.username');
                echo $form->input('User.password');
                echo $form->input('User.password2');
                echo $form->input('User.email');
        ?>
        </fieldset>
<?php echo $form->end('Submit');?>
</div>


Dave

-----Original Message-----
From: Janne [mailto:janne.yli...@gmail.com] 
Sent: January-27-09 12:41 PM
To: CakePHP
Subject: Separating user and profile tables


Hi,

I´m doing a pretty simple test project with Cake and having some serious
problems. I think the solution may be really simple, but I just cant solve
it by myself.

What I want is simple one-to-one relation between user and profile tables.
When user registers to system, his/hers username and password are saved in
user table and some profile related stuff to the profile table. So I want to
separate example phone number and email address to different table. And of
course this profile record should be created automatically with user_id when
registered.

So obviosly it is easy to create this action and view to create user, which
is saved to user-table. I also know how to define this one-to- one relation,
that profile belongs to user and profile really has this user_id field. But
how can I create this profile row and save example email address there in
this same action. I think I should add email field to the view and then
somehow add that to profile table with user id.

Btw, I´m trying this with freshly baked default controllers and views.
Models are working like they should be.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to