2014-12-12 09:59:33 5596次浏览 5条回答 0 悬赏 5 金钱

$this->save() 的参数有 True 和 False,请教他们都代表什么意思啊?

补充于 2014-12-12 11:01

非常感谢,Thanks

最佳答案

  • 回答于 2014-12-12 10:16 举报

    追踪代码是:true 插入 false 更新

        if ($this->getIsNewRecord()) {
            return $this->insert($runValidation, $attributeNames);
        } else {
            return $this->update($runValidation, $attributeNames) !== false;
        }
    
  • 回答于 2014-12-12 13:10 举报

    这个, API 的注释已经相当清楚了,true 验证数据, 会调用 validate() 方法,false 不验证数据,直接存储,至于是更新数据,还是插入数据,就看 $this->getIsNewRecord() 的返回结果了,跟 save 方法的参数没有丁点关系

  • 回答于 2014-12-12 13:12 举报

    save 方法的定义

    boolean save( $runValidation = true, $attributeNames = null )
    
  • 回答于 2014-12-19 08:40 举报

    采纳了一个明显错误的答案……

    1 条回复
    回复于 2015-01-07 14:10 回复

    那段时间我还没用YII,只是追踪进去看是看到 $this->getIsNewRecord() 。误导了楼主了

您需要登录后才可以回答。登录 | 立即注册
YiiSoEasy
CEO

YiiSoEasy 中国

注册时间:2014-11-25
最后登录:2024-03-25
在线时长:188小时51分
  • 粉丝209
  • 金钱10942
  • 威望120
  • 积分14022

热门问题