$data['User']['id'] will be null because the User hasn't even been created yet. Why don't you just save it to the session before your setFlash() call? Use Model::getLastInsertId()
On Wed, Jul 22, 2009 at 12:36 AM, damanlovett<[email protected]> wrote: > > I'm a noob so this my be a really stupid question. I'm trying to grab > data and place it in sessions when a user is created. I tried to use > a beforeSave() so that I can reuse the id, but the session is empty. > Please help. Thans > > Here's my code > > function beforeSave(){ > > if(!empty($this->data)){ > $this->Session->write('Fac', $this->data['User'] > ['id']); > > } > return true; > } > > function add() { > if (!empty($this->data)) { > $this->User->create(); > if ($this->User->save($this->data)) { > $this->Session->setFlash(__('The User has been > saved', true)); > $this->redirect(array('action'=>'index')); > } else { > $this->Session->setFlash(__('The User could > not be saved. Please, > try again.', true)); > } > } > $positions = > $this->User->Position->find('list',array('conditions' > => array('type' => 'position'))); > $classifications = $this->User->Classification->find('list', > array > ('conditions' => array('type' => 'class'))); > $groups = $this->User->Group->find('list', array('conditions' > => > array('id >' => '1'))); > $this->set(compact('positions', 'classifications', 'groups')); > } > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
