douju8782 2011-03-14 02:19
浏览 26
已采纳

Cakephp指定要保存的字段?

In my model, I have a field called difficulty, but no matter what value i give it, a value of 1 is saved to the database.

I did a datadump on the model before I did a save() and this is what I see:

Array
(
    [title] => testtt34
    [serves] => 32
    [prep_time] => 32
    [cooking_time] => 32
    [difficulty] => 4
)

But the sql query cakephp generated is this:

INSERT INTO `recipes` (`title`, `serves`, `prep_time`, `cooking_time`, `difficulty`, `modified`, `created`) VALUES ('testtt34', 32, 32, 32, 1, '2011-03-13 19:15:16', '2011-03-13 19:15:16')

What the heck? even though difficulty is clearly 4 in my datadump, the sql generated inserted difficulty = 1.

//Do some checking to make sure the data is from proper location
$this->data = Sanitize::clean($this->data);
$this->Recipe->data = $this->data;
//error checking
$this->pa($this->Recipe->data['Recipe']);
if ($this->Recipe->save())
{
    //Blah do some stuff
}
  • 写回答

1条回答 默认 最新

  • dshxbrzgi090608692 2011-03-14 02:27
    关注

    Nevermind I accidentally set difficulty's type as TINYINT(1) meant to do TINYINT(3), well that fixed it. Very dumb mistake.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Labview机器人问题
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr