问题
Beginners question in cakePHP, it drives me mad, I tried so much but can't get this working in cakePHP. I want to print 'Train station nearby' if the boolean is set. The database has the field 'train' bit(1) when doing a
<?php echo h($property['Property']['train']); ?>
it shows 1 but in the database it is 0, WHY is it printing 1 instead of 0
<?php if($property['Property']['train'] == true ) echo 'Train station nearby'; ?>
This output works all the time, but of course it is not true! Anyone please, is this something to do with the fact it is a bit(1) field or am I doing something wrong. Please keep in mind I am a beginner, and I did try a lot of php examples with booleans, but just can't work out why it is not working for me in cakePHP. Thanks for looking into this.
回答1:
If you are using mysql use tinyint(1)
for the field which is emulated as boolean.
回答2:
According to this ticket bit type fields are currently not supported by CakePHP. Instead, use the boolean type for boolean values.
来源:https://stackoverflow.com/questions/15868828/cakephp-print-a-boolean