zoukankan      html  css  js  c++  java
  • ActiveRecord的生命周期

    ActiveRecord的生命周期,通过方法重写和插入我们需要的业务逻辑来达到我们对程序的控制。

    示例:

    1,beforeSave()

    public function beforeSave($insert)
    {
    if(parent::beforeSave($insert))
      {
    if($insert)
           {
          $this->create_time = time();
          $this->update_time = time();
        }
    else
        {
          $this->update_time = time();
        }
    return true;
      }
    else
      {
    return false;
      }

    2,afterFind()

    public function afterFind()
    {
    parent::afterFind();
    $this->_oldTags = $this->tags;
    }


    3,afterSave()

    public function afterSave($insert, $changedAttributes)

    {
    parent::afterSave($insert, $changedAttributes);
    Tag::updateFrequency($this->_oldTags, $this->tags);
    }


    4,
     afterDelete()

    public function afterDelete()
    {
    parent::afterDelete();
    Tag::updateFrequency($this->tags, '');
    }

  • 相关阅读:
    排名第一、第二的OCR软件
    补码输出
    枚举 与 枚举的应用
    动态构造结构体数组
    c 冒泡排序
    strcpy
    typedef用法
    C 结构体小结
    int 占一个机器字长
    SQL Server创建视图——视图的作用
  • 原文地址:https://www.cnblogs.com/peteremperor/p/6419915.html
Copyright © 2011-2022 走看看