cakephp print a boolean

邮差的信 提交于 2020-01-24 22:01:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!