CakePHP saveField INT 列中的 NULL 值

标签 cakephp

我想更新一列,该列是具有 NULL 值的 INT。我使用 CakePHP 2.3 和 saveField('field', 'value') 方法。

这是我的代码:

$this->Customer->id = $customer_id;
if ($this->Customer->saveField('account_id', 'NULL')) {
     //Do some stuff
}

因此,当我输入“NULL”时,该行将更新为 0。我尝试使用不带引号的 NULL,但该行未更新。

编辑: 数据库中的字段接受 NULL 值。

你有什么想法吗?

谢谢

最佳答案

不要将 'NULL' 作为字符串传递,而是作为 null 值传递:

if($this->Customer->saveField('account_id', null))
{
  //do some stuff
}
else
{
  //do you get anything here ?
  debug($this->Customer->validationErrors);
}

关于CakePHP saveField INT 列中的 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630733/

相关文章:

php - 具有多个搜索过滤器的 Cake PHP3 分页

Cakephp:属于关系

mysql - CakePHP 用户登录功能

php - 将 INSERT IGNORE 语句添加到 CAKEPHP saveAll 方法

php - CakePHP 查找最近的日期

Cakephp 每个 Controller 有多个 View

mysql - Cakephp 3,从辅助表中获取详细信息以发送电子邮件

php - cakephp 2.0 特点?

cakephp - CakePHP 2.0 中的错误处理。转义 View 变量

php - Cakephp 3.x 中的分页排序