i tried these codes:

                        $this->Answer->User->save($this->params['data']);
                        $userID = $this->Answers->User->lastInsertId();

but it said

Fatal error: Call to a member function on a non-object in
/home/felix/cake/sdq/controllers/answers_controller.php on line 29

line 29 is: $userID = $this->Answers->User->lastInsertId();


and, my saveUser():
        function saveUser($data)
        {
                if (!empty($data))
                {
                        //prepare
                        $data['User']['ip'] = 
$this->RequestHandler->getClientIP();

                        //save
                        $this->User->save($data);

                        //return
                        return $this->User->getLastInsertID();
                }
        }

Samuel DeVore 写道:

> Also if the models are related you can do
>
> if ($this->Answers->User->save(array('User'=>$userData) {
>      $user_id =$this->Answers->User->lastInsertId();
>      $this->params['data']['otherModelData']['userr_id'] = $user_id;
>      // now do your save of other stuff
>
>
>
> not tested or what ever but gives you the idea, you may want to save
> yourself the overhead of $this->requestAction....
>
> Sam D
>
> still cranky and still and old fart  ;)
> On 8/24/06, Pablo Viojo <[EMAIL PROTECTED]> wrote:
> > Check the object that "/users/saveUser" is returning, I think it's not only
> > an id but a more complex structure.
> >
> > Regards,
> >
> > --
> > Pablo Viojo
> > [EMAIL PROTECTED]
> >  http://pviojo.net
> >
> >
> >
> > On 8/24/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > >
> > > hi, here is my problem: i need to get user_id before saving the answers
> > > of this user, but after i call $userID =
> > > $this->requestAction("/users/saveUser"), i found that the
> > next saving
> > > action just doesn't work, what shall i do please?
> > >
> > >
> > > my models and controllers:
> > >
> > http://cakephp.org/pastes/show/8be29a861266efcf9943c3d5180fcf98
> > >
> > >
> > >
> > >
> > >
> > >
> > > > >
> > >
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to