Re: getLastInsertId or something similar

2009-01-26 Thread mike
so, I was finaly able to do it like this: events controller, after save: $event_id = $this->Event->getLastInsertId(); $this->Session->write('Event.id', $event_id); users view: $event_id = $session->read('Event.id'); echo $form->input('Event.id',array('type' => 'hidden', '

Re: getLastInsertId or something similar

2009-01-21 Thread Webweave
You would only need to use the getLastInsertId() if you had inserted something and then immediately needed to add related data. If your forms walk you through some process which goes to another controller, you'd either need to pass the data along, or fetch it again. Like I said before, I have a

Re: getLastInsertId or something similar

2009-01-21 Thread Yusuf Widiyatmono
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 To: CakePHP Sent: Thursday, January 22, 2009 9:13:48 AM Subject: Re: getLastIns

Re: getLastInsertId or something similar

2009-01-21 Thread mike
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

Re: getLastInsertId or something similar

2009-01-21 Thread Webweave
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 wrote: > eeerrr, this is not working. > > I have this in the User model: > var $hasMany = array ('Event'); > > t

Re: getLastInsertId or something similar

2009-01-19 Thread mike
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', ) ); $thi

Re: getLastInsertId or something similar

2009-01-19 Thread Jon Bennett
> 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->

Re: getLastInsertId or something similar

2009-01-18 Thread mike
thanks for all the responses, sorry for being slow, but I don't understand: > * grab the 'lastInsertId()' of the event record > * pass this to the view to use in your User form, eg User.event_id where do I grab the lastInsertId()? in the event_controller? and then how do I pass it to the user

Re: getLastInsertId or something similar

2009-01-18 Thread Webweave
You don't have to have two forms, you just have to save things in the right order. I do this on one of my volunteer signup (http://volunteercake.sf.net). Before the user is logged in, I display a list of jobs they can sign up for, if they click on the 'signup' link, I take them to a page that doe

Re: getLastInsertId or something similar

2009-01-18 Thread Jon Bennett
> You can't have an Event.user_id if there's no User. You're doing this > backwards. yep, so the order of things (doing it event first would be) * show new event form * on submit, save data to create a new Event record * grab the 'lastInsertId()' of the event record * pass this to the view to

Re: getLastInsertId or something similar

2009-01-17 Thread brian
You can't have an Event.user_id if there's no User. You're doing this backwards. On Sat, Jan 17, 2009 at 5:43 PM, mike wrote: > > The user does not already exist. The event is being created, then > immediately after the user is being created. > > I forgot to mention, it occured to me to save th

Re: getLastInsertId or something similar

2009-01-17 Thread mike
The user does not already exist. The event is being created, then immediately after the user is being created. I forgot to mention, it occured to me to save the user first, then the event, but its just for this specific application we decided to do it this way. So how do I set the value of the

Re: getLastInsertId or something similar

2009-01-17 Thread WebbedIT
If Event belongsTo User then you need a user_id field in the Event table If you have a two part form which first creates an Event then creates a User after submitting the Event part of the form you could then pass $data['Event']['id'] to the User form (will be available after saving the Event dat

Re: getLastInsertId or something similar

2009-01-16 Thread brian
Does the User already exist? Or, is the User being created at the same time as the event? Either way, if you create the event with the Event controller, all you need to do is make sure there's a hidden field for Event.user_id and that its value is set to the User.id. On Fri, Jan 16, 2009 at 11:4

Re: getLastInsertId or something similar

2009-01-16 Thread mike
I'm not sure I understand this. How would the user controller know which event its supposed to be related to? I have the user model set to hasMany Events, and Event belongsTo User. In the view I have the hidden field as suggested. then I tried this: $this->data['Event']['user_i

Re: getLastInsertId or something similar

2009-01-16 Thread brian
Whoops! Yes, what Jon said. On Fri, Jan 16, 2009 at 10:43 PM, Jon Bennett wrote: > >> However, wouldn't it make more sense to submit the User info before >> the Event info? I assume that a User hasMany Event. In which case, >> you'd have the User submit their info and ensure that >> $this->d

Re: getLastInsertId or something similar

2009-01-16 Thread Jon Bennett
> However, wouldn't it make more sense to submit the User info before > the Event info? I assume that a User hasMany Event. In which case, > you'd have the User submit their info and ensure that > $this->data['User']['id'] was set before rendering (not redirect to) > the Event form view, whic

Re: getLastInsertId or something similar

2009-01-16 Thread brian
After the Event info has been submitted, if your models are set up correctly, you should get the Event id included in your User form if it's in $this->data['Event']['id'] User form: $form->hidden('Event.id') However, wouldn't it make more sense to submit the User info before the Event info? I as

getLastInsertId or something similar

2009-01-16 Thread mike
I have a multi page input form thingy - on the first page, the user inputs some event information, then clicks next, this information is saved, then on the next page, the user inputs some user information, clicks save, and this information is saved. The issue is, now the event info has to be asso