Php 更新类别id为0的记录

Php 更新类别id为0的记录,php,cakephp,Php,Cakephp,我将category_id设置为0,category id是自动递增的。所以我在cakephp中更新了这个记录,然后cakephp将插入这个记录而不是更新这个记录 $this->Category->id=$id; $this->Category->save($this->data); 请帮助我…0的Id无效 CakePHP的一个特点是所有标识符都是真实的: /** * Returns the current record's ID * * @param in

我将category_id设置为0,category id是自动递增的。所以我在cakephp中更新了这个记录,然后cakephp将插入这个记录而不是更新这个记录

$this->Category->id=$id;
$this->Category->save($this->data);
请帮助我…

0的Id无效 CakePHP的一个特点是所有标识符都是真实的:

/**
 * Returns the current record's ID
 *
 * @param integer $list Index on which the composed ID is located
 * @return mixed The ID of the current record, false if no ID
 */
public function getID($list = 0) {
    if (empty($this->id) || ...) {
        return false;
    }
    ...
因此,尝试使用id为0进行保存将不起作用,即使存在id为0的行,也会导致Cake尝试插入。

id为0的行无效 CakePHP的一个特点是所有标识符都是真实的:

/**
 * Returns the current record's ID
 *
 * @param integer $list Index on which the composed ID is located
 * @return mixed The ID of the current record, false if no ID
 */
public function getID($list = 0) {
    if (empty($this->id) || ...) {
        return false;
    }
    ...

因此,尝试使用id为0进行保存将不起作用,导致Cake尝试插入,即使存在具有该错误id的行。

不确定我是否正确理解您的意思,但如果您希望更新category_id=0的所有记录,则此代码将有效:

$this->Category->updateAll(
    $this->data,
    array('Category.category_id' => 0)
);

不确定我是否正确理解您,但如果您希望更新category_id=0的所有记录,则此代码将非常有效:

$this->Category->updateAll(
    $this->data,
    array('Category.category_id' => 0)
);

如果id大于0,Cakephp将更新记录,否则将插入新记录。因此,请尝试将id 0更改为大于0。
试试这个。

如果id大于0,Cakephp将更新记录,否则将插入新记录。因此,请尝试将id 0更改为大于0。
试试这个。

确保您已经为记录设置了id,或者将id与记录一起传递。I pass id=0,并且id在数据库表中是自动递增的。在这种情况下,错误会发生其他明智的工作。如果我没有理解错误,您不应该更新自动增量列。为什么要这样做?我不更新自动递增列,但我根据类别id更新类别名称。请添加$this->数据值。确保您已为记录设置了id或将id与记录一起传递。我传递id=0,并且id在数据库表中是自动递增的。在这种情况下,错误会发生其他明智的工作。如果我没有理解错误,您不应该更新自动增量列。为什么要这样做?我不更新自动递增列,但我根据类别id更新类别名称。请添加$this->data值。