First, you really don't want to read the session from the view, it should be done from the controller.
Second, the error you are getting sounds like the value wasn't set in the session, so either you are referencing what you set incorrectly, or you need to query for it. The last inserted ID will only contain a value after you insert a record, so if you hit the page without inserting, your session value won't be populated (so you'd need to do a query to get it). On Jan 11, 4:38 pm, Steppio <[email protected]> wrote: > Thanks alot buddy, thats definatly tightened things up but im still > getting the odd error. Might just be me. Thanks for your help matey! > > On Jan 8, 8:16 pm, "Mark (Germany)" <[email protected]> > wrote: > > > always make sure that you check on or cast to whatever you need, > > especially reading from session! > > especially as type safety (as in java) is not one of PHP's strong > > points > > > if it is an integer id you need to have, use (int) casting: > > $user_id = (int)$session->read('User.id') > > > this way your input won't be filled with an array or something > > in this case, it will cast to a 0 (zero), if no valid entry was given > > the DB will prefer that one over just an empty string anyway for an > > INT field > > > if it is a UUID, you could cast like this: > > $user_id = (string)$session->read('User.id') > > > and if you want to populate a dropdown box (where you want to have an > > array), do this: > > $dropdownItems = (array)$session->read('User.roles') > > > etc. > > > On 8 Jan., 17:13, Steppio <[email protected]> wrote: > > > > Hi everybody. I've been getting gip from this cheeky little number for > > > a while now, was just wondering if anybody has any insights into how i > > > could solve this problem. > > > The problem is that i'm passing the lastInsertId into the session and > > > trying to pull it out in different views, and it works alot of the > > > time, but sometimes it just has a tissy fit. I keep getting > > > this error message when passing the ID across controller/views: > > > > SQL Error: 1366: Incorrect integer value: '' for column 'user_id' at > > > row > > > > The site takes the users username and password, then goes onto a > > > different set of controller/views for Details, then onto Duties, and > > > finally Terms and Conditions. I find the problem happens most when i > > > reload one of the pages, for instance when im adding Details and it > > > times-out or i just reload the page. It's sometimes as if it's not > > > writing correctly to the Session, but then again it works other times. > > > > Here's an example of how i read the session in a view: > > > <?php $user_id = $session->read('User.id');?> > > > <?php echo $form->input('user_id', array('type' => > > > 'hidden', 'value' => $user_id));?> > > > > And in a controller: > > > $this->Session->read('User.id') > > > > Any suggestions? Any help would be greatly appreciated! > > > Thank you > > > Steppio > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
