验证后保存原图
@throws \yii\base\Exception
500002
public function afterValidate()
    {
        //保存原图
        Image::crop($this->file->tempName, $this->width, $this->height, [$this->x, $this->y])->save($this->getOriginalImage(), ['quality' => 100]);
        parent::afterValidate();
    }
1011513
protected function beforeSave() 
	{
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);
		$currentAction = strtolower(Yii::app()->controller->id.'/'.Yii::app()->controller->action->id);

		if(parent::beforeSave()) {
			$this->construction_date = date('Y-m-d', strtotime($this->construction_date));
			if($currentAction == 'settings/general')
				$this->construction_text = serialize($this->construction_text);
			$this->event_startdate = date('Y-m-d', strtotime($this->event_startdate));
			$this->event_finishdate = date('Y-m-d', strtotime($this->event_finishdate));
		}
		return true;
	}
696865
public function run()
    {
        $action = Yii::$app->getRequest()->get('action', null);
        switch ($action) {
            case 'config':
                $result = Json::encode($this->config());
                break;
            /* 上传图片 */
            case 'uploadimage':
                /* 上传涂鸦 */
            case 'uploadscrawl':
                /* 上传视频 */
            case 'uploadvideo':
                /* 上传文件 */
            case 'uploadfile':
                $result = $this->fileUpload();
                break;
            /* 抓取远程文件 */
            case 'catchimage':
                $result = $this->saveRemote();
                break;
            default:
                $result = Json::encode(array('state' => '请求地址出错'));
                break;
        }
        /* 输出结果 */
        $callback = Yii::$app->getRequest()->get('callback', null);
        if ($callback) {
            if (preg_match("/^[\w_]+$/", $callback)) {
                $result = htmlspecialchars($callback) . '(' . $result . ')';
            } else {
                $result = Json::encode(array('state' => 'callback参数不合法'));
            }
        }
        return $result;
    }
20882
function save()
    {
        $this->_save = false;
        if ($this->_change == 0 or $this->_change == 1)
        {
            if ($this->db->insert($this->_data, $this->table) === false)
            {
                return false;
            }
            //改变状态
            $this->_change = 1;
            $this->_current_id = $this->db->lastInsertId();
        }
        elseif ($this->_change == 2)
        {
            $update = $this->_update;
            unset($update[$this->primary]);
            if ($this->db->update($this->_current_id, $update, $this->table, $this->primary) === false)
            {
                return false;
            }
        }
        $this->notify();
        return true;
    }
904026
public function saveGridOrder() {
        if (!isset(Yii::$app->session[$this->sessionVarName])) {
            Yii::$app->session[$this->sessionVarName] = '';
        }

        if (Yii::$app->request->get($this->getVarName) !== null) {
            Yii::$app->session[$this->sessionVarName] = Yii::$app->request->get($this->getVarName);
        }
    }
453712
public function run()
    {
        if (yii::$app->getRequest()->getIsPost()) {//只允许post删除
            $id = yii::$app->getRequest()->get($this->paramSign, null);
            $param = yii::$app->getRequest()->post($this->paramSign, null);
            if($param !== null){
                $id = $param;
            }

            if( yii::$app->getRequest()->getIsAjax() ){
                yii::$app->getResponse()->format = $this->ajaxResponseFormat;
            }
            if (! $id) {
                throw new BadRequestHttpException(yii::t('app', "Id doesn't exit"));
            }
            if(is_array($id)){
                $ids = $id;
            }else{
                $ids = explode(',', $id);
            }

            $errorIds = [];
            /* @var $model yii\db\ActiveRecord */
            $model = null;
            foreach ($ids as $one) {
                $model = call_user_func([$this->modelClass, 'findOne'], $one);
                if ($model) {
                    $model->setScenario($this->scenario);
                    if (! $result = $model->delete()) {
                        $errorIds[] = $one;
                    }
                }
            }
            if (count($errorIds) == 0) {
                if( !yii::$app->getRequest()->getIsAjax() ) return $this->controller->redirect(yii::$app->getRequest()->headers['referer']);
                return ['status'=>true,'msg'=>yii::t('app','Success')];
            } else {
                $errors = $model->getErrors();
                $err = '';
                foreach ($errors as $v) {
                    $err .= $v[0];
                }
                if ($err != '') {
                    $err = '.' . $err;
                }
                throw new UnprocessableEntityHttpException('id ' . implode(',', $errorIds) . $err);
            }
        } else {
            throw new MethodNotAllowedHttpException(yii::t('app', "Delete must be POST http method"));
        }
    }
370526
public function save()
    {
        $this->exitIfModelNotSet();

        if (!$this->model->exists) {
            throw new \Exception('Model not persisted yet');
        }
        $document = $this->model->getDocumentData();

        $params = [
            'id'    => $this->model->getKey(),
            'type'  => $this->model->getDocumentType(),
            'index' => $this->model->getDocumentIndex(),
            'body'  => $document,
        ];

        return $this->connection->indexStatement($params);
    }
741044
public function beforeSave($event)
    {
        list($id, $attribute) = $event->data;
        if (isset(self::$_executed[$id])) {
            return;
        }
        /* @var $object \yii\db\ActiveRecord */
        $object = $event->sender;
        if (is_string($this->format) && method_exists($object, $this->format)) {
            $value = call_user_func([$object, $this->format], $object, $attribute);
        } else {
            $value = is_callable($this->format) ? call_user_func($this->format, $object, $attribute) : $this->format;
        }
        $group = md5(serialize([
            'class' => $this->unique ? get_class($object) : false,
            'group' => $this->group,
            'attribute' => $attribute,
            'value' => $value
        ]));
        $model = Autonumber::findOne($group);
        if ($model) {
            $number = $model->number + 1;
        } else {
            $model = new Autonumber([
                'group' => $group
            ]);
            $number = 1;
        }
        $model->update_time = time();
        $model->number = $number;
        if ($value === null) {
            $object->$attribute = $number;
        } else {
            $object->$attribute = str_replace('?', $this->digit ? sprintf("%0{$this->digit}d", $number) : $number, $value);
        }
        self::$_executed[$id] = true;
        try {
            $model->save(false);
        } catch (\Exception $exc) {
            $event->isValid = false;
            if ($this->throwIsStale || !($exc instanceof StaleObjectException)) {
                throw $exc;
            }
        }
    }
910204
public function afterSave()
    {
        /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */
        $owner = $this->owner;
        $event = new HasPropertiesEvent();
        $event->model = $owner;
        HasPropertiesEvent::trigger(self::class, self::EVENT_AFTER_UPDATE, $event);
        if ($this->autoSaveProperties === true) {
            $models = [&$owner];
            PropertiesHelper::storeValues($models);
        }
        $owner->changedProperties = [];
        $owner->propertiesValuesChanged = false;

        // check for auto added property groups
        $owner->ensurePropertyGroupIds();
        $autoAddedGroups = PropertyGroup::getAutoAddedGroupsIds(
            PropertiesHelper::applicablePropertyModelId($owner)
        );

        foreach ($autoAddedGroups as $id) {
            if (!in_array($id, $owner->propertyGroupIds)) {
                /** @var PropertyGroup $propertyGroup */
                $propertyGroup = PropertyGroup::loadModel(
                    $id,
                    false,
                    true,
                    86400,
                    new ServerErrorHttpException("Property group with id $id not found"),
                    true
                );
                $owner->addPropertyGroup($propertyGroup);
            }
        }
    }
1042409
public function save()
    {
        $module = isset(Yii::$app->controller) ? Yii::$app->controller->module : null;
        if ($this->operation === self::OP_CREATE) {
            $dir = dirname($this->path);
            if (!is_dir($dir)) {
                if ($module instanceof \yii\gii\Module) {
                    $mask = @umask(0);
                    $result = @mkdir($dir, $module->newDirMode, true);
                    @umask($mask);
                } else {
                    $result = @mkdir($dir, 0777, true);
                }
                if (!$result) {
                    return "Unable to create the directory '$dir'.";
                }
            }
        }
        if (@file_put_contents($this->path, $this->content) === false) {
            return "Unable to write the file '{$this->path}'.";
        }

        if ($module instanceof \yii\gii\Module) {
            $mask = @umask(0);
            @chmod($this->path, $module->newFileMode);
            @umask($mask);
        }

        return true;
    }
1019044
public function actionSignup()
    {
        $request = \Yii::$app->request;
        if ($request->getIsOptions()) {
            return $this->ResponseOptions($this->verbs()['signup']);
        }
        try{
            $model = new SignupForm();
            $model->setAttributes(Yii::$app->request->post());
            $user = $model->signup();
            if ($user !=null) {
                return ["success"=>true,"message"=>"创建成功！"];
            }else{
                return ["success"=>false,"message"=>"参数错误！"];
            }
        }catch(Exception $e){
            throw new Exception($e);
        }



    }
364123
public function save(): Record
    {
        //没有主键字段,则不进行保存
        if (!$this->_primaryKey) {
            return $this;
        }

        //获取要写入的数据
        $data = self::dataForWrite();

        //本表的主键字段
        $pk = $this->_primaryKey;

        //如果没有主键字段,插入数据
        if (!isset($data[$pk])) {
            $id = $this->_table->insert($data);
            $this->_data[$pk] = $id;
            $this->{$pk} = $id;
            return $this;
        }

        //以下是修改,主键的值
        $pkValue = $data[$pk];

        //与原始数据对比,挑出有变化的部分
        $data = array_diff_assoc($data, $this->_old);

        //如果有变化,只修改有变化的部分
        if (!empty($data)) {
            $this->_table->update($data, [$pk => $pkValue]);
        }

        //检查关联字段,逐个保存
        self::saveRelation();

        return $this;
    }
1360443
public function save()
    {
        if (Yii::$app instanceof Application) {
            Media::updateAll([
                'model_id' => $this->owner->getPrimaryKey(),
            ], [
                'AND',
                ['=', 'model', $this->owner::className()],
                ['IN', 'id', Yii::$app->request->post($this->name, [])],
            ]);
        }
    }
765516
protected function beforeSave() 
	{
		$currentAction = strtolower(Yii::app()->controller->id.'/'.Yii::app()->controller->action->id);
		
		if(parent::beforeSave()) {
			$meta_path = "public";
			$this->meta_image = CUploadedFile::getInstance($this, 'meta_image');
			if($this->meta_image instanceOf CUploadedFile) {
				$fileName = 'meta_'.time().'.'.$this->meta_image->extensionName;
				if($this->meta_image->saveAs($meta_path.'/'.$fileName)) {
					if($this->old_meta_image != '')
						@unlink($meta_path.'/'.$this->old_meta_image);
					$this->meta_image = $fileName;

					//create thumb image
					Yii::import('ext.phpthumb.PhpThumbFactory');
					$pageImg = PhpThumbFactory::create($meta_path.'/'.$fileName, array('jpegQuality' => 90, 'correctPermissions' => true));
					$pageImg->resize(700);
					$pageImg->save($meta_path.'/'.$fileName);
				}
			}
			
			if($currentAction == 'meta/edit')
				$this->map_icon_size = serialize($this->map_icon_size);
			
			if($currentAction == 'meta/twitter') {
				$this->twitter_photo_size = serialize($this->twitter_photo_size);
				$this->twitter_iphone = serialize($this->twitter_iphone);
				$this->twitter_ipad = serialize($this->twitter_ipad);
				$this->twitter_googleplay = serialize($this->twitter_googleplay);
			}
		}
		return true;
	}
1035825
public function save() {
		if($this->persistent) {
			$action = $this->{'update'};
			$action->directCall($this->attrsForApi($action));
			
		} else {
			// insert
			$action = $this->{'create'};
			$ret = new Response($action, $action->directCall($this->attrsForApi($action)));
			
			if($ret->isOk()) {
				$this->attrs = array_merge($this->attrs, (array) $ret->getResponse());
				
			} else {
				throw new Exception\ActionFailed($ret, "Action '".$action->name()."' failed: ".$ret->message());
			}
			
			$this->persistent = true;
		}
	}
1207776
public function save()
    {
        if ($this->validate() && $this->file instanceof UploadedFile) {
            try {
                if (($uploader = $this->file->save()) != false) {
                    $this->file = $uploader->getUrl();
                    return true;
                } else {
                    $this->addError('file', Yii::t('yuncms', 'Audio file storage failed.'));
                }
            } catch (FileExistsException $e) {
                $this->addError('file', $e->getMessage());
            } catch (ErrorException $e) {
                $this->addError('file', $e->getMessage());
            } catch (InvalidConfigException $e) {
                $this->addError('file', $e->getMessage());
            }
        }
        return false;
    }
685936
protected function beforeSave() 
	{
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);

		$location = $controller;
		
		if(parent::beforeSave()) {
			if($this->isNewRecord || (!$this->isNewRecord && !$this->name)) {
				$name=new SourceMessage;
				$name->message = $this->name_i;
				$name->location = $location.'_title';
				if($name->save())
					$this->name = $name->id;

				$this->slug = $this->urlTitle($this->name_i);
				
			} else {
				$name = SourceMessage::model()->findByPk($this->name);
				$name->message = $this->name_i;
				$name->save();
			}

			$this->sitetype_access = serialize($this->sitetype_access);
			$this->userlevel_access = serialize($this->userlevel_access);
		}
		return true;
	}