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