Cricket's way isn't the best way to do it in cake.

What you should do is make use is the afterSave callback in the user
model.

function afterSave($created) {
      if($created ==true) {
           $data = array('Account' => arrray('user_id' => $this->id));
           $this->Account->save($data);
      }
}

On Jul 13, 1:57 am, cricket <zijn.digi...@gmail.com> wrote:
> On Mon, Jul 12, 2010 at 9:49 AM, Omid <omid.za...@gmail.com> wrote:
> > Hi
> > I am new to cake php and as a practice I am working on one simple
> > project.
> > I have tree model user, account and contact as below. (There is only
> > one form for user registration and no form for add action to account).
>
> > user model :
> >        var $name = 'User';
> >        var $useTable = 'users';
> >        var $hasOne = array('accounts');
> >        var $hasMany = array('contacts');
>
> > I am saving users email as the username in this model,(I am using Auth
> > component)
>
> > and account:
>
> >        var $name = 'Account';
> >        var $belongsTo = array(
> >                'User' => array(
> >                    'className'    => 'User',
> >                    'foreignKey'    => 'user_id'
> >                )
> >            );
>
> > I need to create a record in account when a user is registering
> > (register action of controller) (or when user is verifying their email
> > address - verify action of controller) the information in this model
> > should calculated. (no form involved). there is one field in account
> > called user credit. which I need to update it whenever user add a
> > contact(again b).
>
> From within UsersController:
>
> $data = array(
>     'Account' => array(
>         'user_id' => $this->User->id,
>         ...
>     )
> );
> $this->User->Account->save($data);
>
> Of course, $this->User->id will need to be set. Or use $id, or whatever.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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