如何在publicSave中获取公共函数中的id

时间:2012-11-30 21:00:03

标签: cakephp cakephp-appmodel

我需要在一个模型中获取在beforeSave函数()中添加或修改的最后一个id。我试试这个:

$this->model->id;$this->data['model']['short']但它不起作用。

这在cakephp中是正确的,还是有另一种方法可以在模型中获取id?

1 个答案:

答案 0 :(得分:1)

我在模型中使用此功能来存储模型的已保存ID:

function afterSave($created){   
    if($created){
        $this->inserted_ids[] = $this->getInsertID();
    }
    return true;
}

然后只需使用$this->ModelName->inserted_ids;

获取已保存的ID
相关问题