you can only get the value of getLastInsertId() method after saving something...
you have to do this before $this->User->Event->save($this_data); $last_event_id = $this->User->Event->getLastInsertId(); and this getLastInsertId() method is only working for save() method to insert new record to events table in database. for using save() method to update a record, the getLastInsertId, will not give you anything too ----------------------------------------------------------------------------------------------- is this the answer that you mean? sorry if i am mistaken what your question. Best Regards Yusuf Widiyatmono Software Engineer Phone +62 (361) 755 025 Facsimile +62 (361) 755 024 Mobile +62 813 2126 4488 www.mitrais.com ________________________________ From: mike <[email protected]> To: CakePHP <[email protected]> Sent: Thursday, January 22, 2009 9:13:48 AM Subject: Re: getLastInsertId or something similar does this mean I can't use getLastInsertId() if I inserted the event in another controller? (this was one of my original questions) In the events controller, I save the event, then redirect to the user view. In the user controller is where I'm trying to get the event_id I just inserted. On Jan 21, 4:49 pm, Webweave <[email protected]> wrote: > It will only return a value after you do an insert (a save of the new > Event). > > Post the action you are having trouble with, and perhaps we can spot > the issue. > > On Jan 19, 3:41 pm, mike <[email protected]> wrote: > > > > > eeerrr, this is not working. > > > I have this in the User model: > > var $hasMany = array ('Event'); > > > this in the event model: > > var $belongsTo = array ( > > 'User' => array( > > 'className' => 'User', > > 'foreignKey' => 'creator_id', > > ) > > ); > > > $this->User->Event->getLastInsertId() in the users controller returns > > nothing! > > > what am I missing?? > > > On Jan 19, 3:01 am, "Jon Bennett" <[email protected]> wrote: > > > > > where do I grab the lastInsertId()? in the event_controller? and > > > > then how do I pass it to the user view? > > > > provided you've correctly set up your model associations, which I think > > > are: > > > > User hasMany Event > > > Event belongsTo User > > > > From your Users controller you can do: > > > > $event_id = $this->User->Event->getLastInsertId(); > > > > hth > > > > jon > > > > -- > > > > jon bennett > > > w:http://www.jben.net/ > > > iChat (AIM): jbendotnet Skype: jon-bennett- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
