【问题标题】:how to get ids of the rows updated by updateAll() function in cakephp?如何获取 cakephp 中 updateAll() 函数更新的行的 ID?
【发布时间】:2012-04-09 13:38:34
【问题描述】:

我正在 cakephp 中开发一个应用程序。我需要使用 cakephp 中的 updateAll() 函数获取所有已更新行的 ID。任何建议将不胜感激。谢谢。。

这是我应该在我的应用模型中做的事情

class AppModel extends Model {

    var $infos = array();

    function updateAll($fields, $conditions = true) {
        $this->$infos = $this->find('all', array('conditions' => $conditions));
        $return = parent::updateAll($fields, $conditions);
        $this->afterUpdateAll();
        return $return;
    }


    function afterUpdateAll(){
        foreach ($this->$infos as $info) {
            //do something
        }
    }

}

这行得通吗..?

【问题讨论】:

    标签: php mysql cakephp cakephp-1.3 cakephp-model


    【解决方案1】:

    你必须发出一个find,传递你传递给updateAll的相同条件。

    如果更新操作更改了条件中使用的任何列中的数据,您应该在调用updateAll之前使用find

    【讨论】:

    • @vin.it,您发布的代码有一个问题,请参阅我的更新答案。
    • thanx.. 会让你知道的.. :)
    【解决方案2】:

    如果您 UPDATE uncial 行 - 您可以在 UPDATE 之后再次 SELECT 他们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-28
      • 1970-01-01
      • 2021-10-11
      • 2010-11-26
      • 1970-01-01
      • 2011-07-14
      • 2012-04-13
      • 1970-01-01
      相关资源
      最近更新 更多