I'm a noob in cakephp. Working on an opensource project. The issue is:When I'm inserting a value for a certain table ( "is_adjusted" (tinyint)), the my php code executes successfully. But the table is only taking 0 or 1 as it's value. Sample code : $reward = $ta_customer_reward->newEntity(); $string_reward = var_export($reward, true); $reward->customer_email = $some_preset_xyz; $reward->reward_amount = $some_preset_xyz;; $reward->particulars = $some_preset_xyz; .. .. .. // This is_adjusted is the culprit. $reward->is_adjusted = 2; $reward = $ta_customer_reward->save($reward);Now whenever I save (insert) this in db, this is stored as 1. I'm stuck for three days. Things I've checked:No default value in db for is_adjusted.No other function is overwriting that field.*** 1.The reward object looked quite unusual to me. There is a property name dirty. I'm still studying this. But for now it seems to me as some cakephp db object structure.This is cakephp v 3. xyz*** 解决方案 This is by CakePHP's design. CakePHP always see tinyint(1) as boolean hence it will always convert your value to true/false hence the 1/0.To overcome this issue, use tinyint(2) instead for your column type. Remember to clear your model cache!CakePHP data type documentation:http://book.cakephp.org/3.0/en/orm/database-basics.html#data-typesBlog post about this:http://blog.room34.com/archives/2649Similar Q&A:CakePHP and tinyint as boolean 这篇关于Cakephp:在插入tinyint字段时.仅获得"0"或"1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-12 08:24