保存数据

@return array
11604
public function actionSave()
    {
        $menu_id = Yii::$app->request->post('menu_id');
        $parent_id = intval(Yii::$app->request->post('parent_id'));
        $text = Yii::$app->request->post('origin_text');
        $title = Yii::$app->request->post('title');
        $url = Yii::$app->request->post('url');
        $view_package = Yii::$app->request->post('view_package');
        $expanded = intval(Yii::$app->request->post('is_expand'));
        $closable = intval(Yii::$app->request->post('closable'));
        $is_folder = intval(Yii::$app->request->post('is_folder'));
        $is_open_url = intval(Yii::$app->request->post('is_open_url'));
        $is_open_target = intval(Yii::$app->request->post('is_open_target'));
        $is_every_open = intval(Yii::$app->request->post('is_every_open'));
        $is_hide = intval(Yii::$app->request->post('is_hide'));
        $display_order = Yii::$app->request->post('display_order');
        $params = Yii::$app->request->post('params');
        $note = Yii::$app->request->post('note');
        $status = intval(Yii::$app->request->post('status'));

        $parent_id = $parent_id ? $parent_id : null;

        if ($parent_id) {
            if ($parent_id == $menu_id) {
                return $this->renderError('不能把自己当作父级');
            } else {
                $menu = DpAdminMenu::find()
                    ->findByMenuId($parent_id)
                    ->asArray()
                    ->one();;
                if (!$menu) {
                    return $this->renderError('父级不存在');
                }
            }
        }

        $saveData = [
            'parent_id' => $parent_id,
            'text' => $text,
            'title' => $title,
            'url' => $url,
            'view_package' => $view_package,
            'expanded' => $expanded,
            'closable' => $closable,
            'is_folder' => $is_folder,
            'is_open_url' => $is_open_url,
            'is_open_target' => $is_open_target,
            'is_every_open' => $is_every_open,
            'is_hide' => $is_hide,
            'display_order' => $display_order,
            'params' => $params,
            'note' => $note,
            'status' => $status,
        ];
        if ($menu_id) {
            $obj = DpAdminMenu::find()
                ->findByMenuId($menu_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminMenu();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }

        // 自动给系统用户添加菜单权限
        if (!$menu_id) {
            $users = DpAdminUser::find()
                ->findByIsSystem(1)
                ->asArray()
                ->all();
            foreach ($users as $user) {
                $relationExists = DpAdminUserMenuRelation::find()->andWhere([
                    'user_id' => $user['user_id'],
                    'menu_id' => $obj->menu_id,
                ])->exists();
				if (!$relationExists) {
					$linkObj = new DpAdminUserMenuRelation();
					$linkObj->setAttributes([
						'user_id' => $user['user_id'],
						'menu_id' => $obj->menu_id,
					]);
					$linkObj->save();
				}
            }
        }
        // 自动给系统用户组添加菜单权限
        if (!$menu_id) {
            $groups = DpAdminGroup::find()
                ->findByIsSystem(1)
                ->asArray()
                ->all();
            foreach ($groups as $group) {
                $relationExists = DpAdminGroupMenuRelation::find()->andWhere([
					'group_id' => $group['group_id'],
					'menu_id' => $obj->menu_id,
                ])->exists();
				if (!$relationExists) {
					$linkObj = new DpAdminGroupMenuRelation();
					$linkObj->setAttributes([
						'group_id' => $group['group_id'],
						'menu_id' => $obj->menu_id,
					]);
					$linkObj->save();
				}
            }
        }

        return $this->renderSuccess('保存成功');
    }
102241
public function save()
    {
        $this->hook('beforeSave', array($this->id));

        $is_update = $this->loaded();
        if ($is_update) {
            $source = array();
            foreach ($this->dirty as $name => $junk) {
                $source[$name] = $this->get($name);
            }

            // No save needed, nothing was changed
            if (empty($source)) {
                return $this;
            }

            $this->hook('beforeUpdate', array(&$source));
        } else {

            // Collect all data of a new record
            $source = $this->get();

            $this->hook('beforeInsert', array(&$source));
        }

        if ($this->controller) {
            $this->id = $this->controller->save($this, $this->id, $source);
        }

        if ($is_update) {
            $this->hook('afterUpdate');
        } else {
            $this->hook('afterInsert');
        }

        if ($this->loaded()) {
            $this->dirty = array();
            $this->hook('afterSave', array($this->id));
        }

        return $this;
    }
835155
public function save() {
        global $DB;
        if (empty($this->id)) {
            $r = (object)array(
                'data' => base64_encode(serialize($this)),
                'expirytime' => time() + (60*60*24),
                'userid' => $this->user->id,
                'instance' => (empty($this->instance)) ? null : $this->instance->get('id'),
            );
            $this->id = $DB->insert_record('portfolio_tempdata', $r);
            $this->expirytime = $r->expirytime;
            $this->save(); // call again so that id gets added to the save data.
        } else {
            if (!$r = $DB->get_record('portfolio_tempdata', array('id' => $this->id))) {
                if (!$this->deleted) {
                    //debugging("tried to save current object, but failed - see MDL-20872");
                }
                return;
            }
            $r->data = base64_encode(serialize($this));
            $r->instance = (empty($this->instance)) ? null : $this->instance->get('id');
            $DB->update_record('portfolio_tempdata', $r);
        }
    }
95178
public function save()
    {
        $ok = $this->consumer->getStorage()->resourceLinkSave($this);
        if ($ok) {
            $this->settingsChanged = false;
        }

        return $ok;
    }
45933
public function save()
    {
        $data = $this->getData();
        if (!$this->currentId)
        {
            $config = $this->getConfig();
            $config->last_id++;
            $this->tableFields->{$this->databaseConfig->getIdentifier()} = $config->last_id;
            array_push($data,$this->tableFields);
            $this->databaseConfig->put($config);
        }
        else
        {
            $this->tableFields->{$this->databaseConfig->getIdentifier()} = $this->currentId;
            $data[$this->currentKey]    = $this->tableFields;
        }
        $this->databaseDocument->put($data);
        return (!$this->currentId) ? $this->setFields() : $this;
    }
581472
public function save()
	{
		$module=Yii::app()->controller->module;
		if($this->content===null)  // a directory
		{
			if(!is_dir($this->path))
			{
				$oldmask=@umask(0);
				$result=@mkdir($this->path,$module->newDirMode,true);
				@umask($oldmask);
				if(!$result)
				{
					$this->error="Unable to create the directory '{$this->path}'.";
					return false;
				}
			}
			return true;
		}

		if($this->operation===self::OP_NEW)
		{
			$dir=dirname($this->path);
			if(!is_dir($dir))
			{
				$oldmask=@umask(0);
				$result=@mkdir($dir,$module->newDirMode,true);
				@umask($oldmask);
				if(!$result)
				{
					$this->error="Unable to create the directory '$dir'.";
					return false;
				}
			}
		}
		if(@file_put_contents($this->path,$this->content)===false)
		{
			$this->error="Unable to write the file '{$this->path}'.";
			return false;
		}
		else
		{
			$oldmask=@umask(0);
			@chmod($this->path,$module->newFileMode);
			@umask($oldmask);
		}
		return true;
	}
1003359
public function save(){
		$json	= $this->data->toJson();
		if( $this->format )
			$json	= ADT_JSON_Formater::format( $json );
		return FS_File_Writer::save( $this->fileName, $json );
	}
245335
public function save(): IResult
    {
        $query = static::query($this);
        $query = $this->parseWhereId($query);
        $data = static::parseSaveData($this);

        // 保存前
        $this->trigger(ModelEvents::BEFORE_SAVE, [
            'model' => $this,
            'data'  => $data,
            'query' => $query,
        ], $this, \Imi\Model\Event\Param\BeforeSaveEventParam::class);

        $result = $query->replace($data);

        // 保存后
        $this->trigger(ModelEvents::AFTER_SAVE, [
            'model' => $this,
            'data'  => $data,
            'result'=> $result,
        ], $this, \Imi\Model\Event\Param\BeforeSaveEventParam::class);

        return $result;
    }
352096
public function saveObjects()
    {
        $post = Yii::$app->request->post();
        $model = $this->owner;
        $url_components = explode("\\", get_class($model));
        $model_name = $url_components[2];

        if(isset($post['Object'])) {
            foreach($post['Object'] as $name => $content) {
                $object = Object::find()->where('Model = :Model and Model_id = :Model_id and name = :name', [':Model'=>$model_name, ':Model_id'=>$model->id, ':name'=>$name])->one();
                if(!$object) {
                    $object = new Object;
                    $object->name = $name;
                    $object->Model = $model_name;
                    $object->Model_id = $model->id;
                }
                $object->content = $content;
                $object->save();
            }
        }
        Yii::$app->cache->delete(get_class($this->owner) . $this->owner->id);
    }
350134
public function actionSave()
    {
        $link_id = \Yii::$app->request->post('link_id');
        $menu_id = \Yii::$app->request->post('menu_id');
        $url_id = \Yii::$app->request->post('url_id');
        $status = \Yii::$app->request->post('status');

        if (!DpAdminMenuUrl::getByUrlId($url_id)) {
            return $this->renderError('菜单URL不存在！');
        }
        $saveData = [
            'menu_id' => $menu_id,
            'url_id' => $url_id,
            'status' => $status,
        ];
        if ($link_id) {
            $obj = DpAdminMenuUrlRelation::find()
                ->findByLinkId($link_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminMenuUrlRelation();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
691334
public function save()
    {
        $lifetime = $this->_params['lifetime'];

        foreach ($this->_update as $mbox => $val) {
            $s = &$this->_slicemap[$mbox];

            try {
                if (!empty($val['add'])) {
                    if ($s['c'] <= $this->_params['slicesize']) {
                        $val['slice'][] = $s['i'];
                        $this->_loadSlice($mbox, $s['i']);
                    }
                    $val['slicemap'] = true;

                    foreach (array_keys(array_flip($val['add'])) as $uid) {
                        if ($s['c']++ > $this->_params['slicesize']) {
                            $s['c'] = 0;
                            $val['slice'][] = ++$s['i'];
                            $this->_loadSlice($mbox, $s['i']);
                        }
                        $s['s'][$uid] = $s['i'];
                    }
                }

                if (!empty($val['slice'])) {
                    $d = &$this->_data[$mbox];
                    $val['slicemap'] = true;

                    foreach (array_keys(array_flip($val['slice'])) as $slice) {
                        $data = array();
                        foreach (array_keys($s['s'], $slice) as $uid) {
                            $data[$uid] = is_array($d[$uid])
                                ? serialize($d[$uid])
                                : $d[$uid];
                        }
                        $this->_cache->set($this->_getCid($mbox, $slice), serialize($data), $lifetime);
                    }
                }

                if (!empty($val['slicemap'])) {
                    $this->_cache->set($this->_getCid($mbox, 'slicemap'), serialize($s), $lifetime);
                }
            } catch (Horde_Exception $e) {
            }
        }

        $this->_update = array();
    }
836162
public function save()
	{
		$result = $this->getClient()->save();
		$ids = array( 'catalog' );

		foreach( $this->getView()->param( 'category/catalog.id', [] ) as $id ) {
			$ids[] = 'catalog-' . $id;
		}

		$this->getContext()->getCache()->deleteByTags( $ids );

		return $result;
	}
795856
public static function save()
    {
        $path = RUNTIME_PATH . Config::get('log.path') . DS;

        if (!is_dir($path)) {
            File::createFolder($path);
        }

        if (isset($_SERVER['HTTP_HOST'])) {
            $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        } else {
            $current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
        }

        $runtime    = round(microtime(true) - HOPE_START_TIME, 10);
        $reqs       = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
        $time_str = ' [运行时间：' . number_format($runtime, 6) . 's] [吞吐率：' . $reqs . 'req/s]';
        $memory_use = number_format((memory_get_usage() - HOPE_START_MEM) / 1024, 2);
        $memory_str = ' [内存消耗：' . $memory_use . 'kb]';
        $file_load  = ' [文件加载：' . count(get_included_files()) . ']';
        $message = '[ info ] [Url：' . $current_uri . ']' . $time_str . $memory_str . $file_load;

        self::record($message);

        $files = File::getFolder($path)['file'];
        if (count($files)) {
            foreach ($files as $file) {
                if ((filemtime($path . $file) + 3600 * 24 * (Config::get('log.time'))) <= time()) {
                    @unlink($path . $file);
                }
            }
        }

        $name = date('Y-m-d') . '.log';
        foreach (self::$log as $value) {
            file_put_contents($path . $name, '[' . date('Y-m-d h:i:s') . '] ' . $value . "\r\n", FILE_APPEND);
        }

        return true;
    }
214905
public static function saveAll() {
		$i = 0;
		foreach (self::$_lPoolDataChange as $sConfig => $lPool) {
			foreach ($lPool as $mID => $aChange) {
				if ($aChange === self::$_lPoolData[$sConfig][$mID]) {
					$o = new $sConfig();
					$o->save();
					$i++;
				}
			}
		}
		return $i;
	}
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;
    }
1371781
public function save()
	{
		$sQuery = $this->_prepare();

		if (preg_match('/INSERT INTO/i', $sQuery)) {

			$oDb = self::connect();
			$oDb->exec($sQuery);
			$this->flush();
			return $oDb->lastInsertId();
		}
		else {

			$this->flush();

			if ($this->_mWhere instanceof Where) { $this->_mWhere->flush(); }

			return self::connect()->exec($sQuery);
		}

	}
992098
public function save()
	{
		$data = $this->get('details');

		if ($data instanceof Registry)
		{
			$this->set('details', $data->toString());
		}
		else if (!is_string($data))
		{
			$this->set('details', json_encode($data));
		}

		$isNew = $this->isNew();
		$result = parent::save();

		if ($result)
		{
			Event::trigger('activity.onLogSave', [$this, $isNew]);
		}

		return $result;
	}