across sessions ...
On Dec 30 2008, 6:40 am, Steppio <stepisgr...@hotmail.com> wrote:
> Ahh thank you very much, i understand now. I've used the following in
> the controller to set the id in the session:
>
> $user_id = $this->User->getLastInsertId();
> $this->Session->write('User.id', $user_id);
>
> And then i used the session helper in the view to retrieve it:
>
> $user_id = $session->read('User.id');
>
> echo $form->input('user_id',array('type' => 'hidden', 'value' =>
> $user_id ));
>
> It still returned a select box with all the ID's in, but its default
> is the last ID, so i set it to hidden.
>
> Say. however, two people signed up to the site simultaneously, would
> this confuse the controller / view if configured this way, i.e. might
> one person end up with the others ID?
>
> Again thank you very much for your help!
>
> On Dec 30, 2:09 pm, majna <majna...@gmail.com> wrote:
>
> >http://api.cakephp.org/class_model.html#2525df39f43db3a76bff482265695d54
>
> > getLastInsertID is wrapper for getInsertID,
> > so getInsertID is a it faster.
> > in controller:
> > $this->set('user_id', $this->User->getInsertID());
>
> > On Dec 30, 2:50 pm, Steppio <stepisgr...@hotmail.com> wrote:
>
> > > Thanks to everyone for the responses its been a big help, i am still
> > > stumped however, are getInsertID and getLastInsertID model functions?
> > > If so how would i pass these to the views?
>
> > > On Dec 29, 4:22 pm, Webweave <webwe...@gmail.com> wrote:
>
> > > > I think you meant $this->User->getLastInsertId();
>
> > > > On Dec 28, 9:59 am, Troy Schmidt <Schmidt.T...@gmail.com> wrote:
>
> > > > > $this->User->getInsertID();
>
> > > > > I don't know about the Auth component as i haven't used it alot. But
> > > > > that would get the last inserted ID. I would just set that variable
> > > > > and include it in the view for the future steps.
>
> > > > > Otherwise it looks like 'user_id' isn't set yet for user
>
> > > > > On Dec 28, 11:11 am, Steppio <stepisgr...@hotmail.com> wrote:
>
> > > > > > Hello everybody, i am totally new to Cake and am finding it quite
> > > > > > difficult to understand all the different parts of it. At the moment
> > > > > > i'm trying to make a three part user registration process, firstly
> > > > > > with the username and password fields, then onto details about the
> > > > > > user, then on to duties they wish to undertake on the site. The only
> > > > > > problem i am having is once the username and password are created it
> > > > > > creates an ID in the users tables, referenced to my other tables as
> > > > > > 'user_id'. What i cannot quite figure out is how, once a user is
> > > > > > created, would i get that user_id into the duties view? What i am
> > > > > > doing at the moment is shown below:
>
> > > > > > function add() {
> > > > > > if (!empty($this->data)) {
> > > > > > $this->User->create();
> > > > > > if ($this->User->saveAll($this->data)) {
> > > > > > $this->Session->setFlash(__('Your Username and Password have been
> > > > > > saved', true));
> > > > > > $cookie = array();
> > > > > > $cookie['user_id'] = $this->Auth->user('user_id');
> > > > > > $this->Session->write('Auth.User', $cookie);
> > > > > > $this->redirect(array('controller'=>'details','action'=>'add'));
> > > > > > } else {
> > > > > > $this->Session->setFlash(__('Your Username and Password could not
> > > > > > be saved. Please, try again.', true));
> > > > > > }
> > > > > > }
> > > > > > }
>
> > > > > > ^users_ controller^
>
> > > > > > I then call this in the 'duties/add' view with:
>
> > > > > > $user_id = $session->read('User_id');
>
> > > > > > echo $form->input('user_id',array('value' => $user_id ));
>
> > > > > > The only problem with this is Cake returns a select box populated with
> > > > > > all of the id's in the user tables. All i want is the ID that has just
> > > > > > been created.
>
> > > > > > This is probably a very simple problem but i've been reading alot on
> > > > > > the internet and just cannot understand how to do it. Any help and
> > > > > > advice would be greatly appreciated!!
>
> > > > > > Yours hopefully,
> > > > > > Steppio
>
>
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment