Example #1
0
 /**
  * (non-PHPdoc)
  * @see \yii\db\BaseActiveRecord::afterSave($insert, $changedAttributes)
  */
 public function afterSave($insert, $changedAttributes)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             //插入
             //如果是单页面,则插入时创建一个单页
             if ($this->type == static::CMS_TYPE_PAGE) {
                 $model = new Page();
                 $model->column_id = $this->id;
                 $model->save(false);
             }
         } else {
             //更新
             if ($this->type == static::CMS_TYPE_PAGE && array_key_exists('deleted', $changedAttributes) && $this->deleted == 1) {
                 //删除单页页分类
                 Page::updateAll(['deleted' => 1], ['column_id' => $this->id]);
             }
         }
         return true;
     } else {
         return false;
     }
 }