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
-~----------~----~----~----~------~----~------~--~---

Reply via email to