保存数据

@return array
198788
public function actionSave()
    {
        $user_id = \Yii::$app->request->post('user_id');
        $menu_ids = \Yii::$app->request->post('menu_ids');
        $username = \Yii::$app->request->post('username');
        $nickname = \Yii::$app->request->post('nickname');
        $source_password = \Yii::$app->request->post('source_password');
        $group_ids = (array)\Yii::$app->request->post('group_ids');
        $is_group_access = \Yii::$app->request->post('is_group_access');
        $is_user_access = \Yii::$app->request->post('is_user_access');
        $is_system = \Yii::$app->request->post('is_system');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        $groupIdsStr = '';
        if ($group_ids) {
            $groupIdsStr = join(',', array_filter($group_ids, function ($groupId) {
                return DpAdminGroup::getByGroupId($groupId);
            }));
        }

        $saveData = [
            'username' => $username,
            'nickname' => $nickname,
            'source_password' => $source_password,
            'group_ids' => $groupIdsStr,
            'is_group_access' => $is_group_access,
            'is_user_access' => $is_user_access,
            'is_system' => $is_system,
            'note' => $note,
            'status' => $status,
        ];
        if ($user_id) {
            $obj = DpAdminUser::find()
                ->where([
                    'user_id' => $user_id
                ])
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminUser();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        // 用户关联的菜单权限更新
        DpAdminUserMenuRelation::deleteByUserId($obj->user_id);
        if ($menu_ids) {
            $menuIdArr = array_filter(StringHelper::explode($menu_ids, ',', true, true), function ($menuId) {
                return DpAdminMenu::getByMenuId($menuId);
            });
            if ($menuIdArr) {
                foreach ($menuIdArr as $menuId) {
                    $linkObj = new DpAdminUserMenuRelation();
                    $linkObj->setAttributes([
                        'user_id' => $obj->user_id,
                        'menu_id' => $menuId,
                    ]);
                    $linkObj->save();
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
134420
public function save()
    {
        $saved = true;

        foreach ($this->_relationsToSave as $model) {
            $model->{$this->relPrimaryKey} = $this->owner->primaryKey;

            if (!$model->save()) {
                $this->owner->addErrors($model->getErrors());

                $saved = false;
            }
        }

        return $saved;
    }
133055
public function actionSave()
    {
        if(Yii::$app->request->isAjax)
        {
            $p = Yii::$app->request->post();
            // after find there are old values (see modules/OneFile::afterFind())
            $model = OneFile::findOne($p['file_id']);
            // so, change them for new defs (see modules/OneFile::beforeSave())
            $model->vars = json_decode($p['defs']);
            $model->save(false, ['defs']);
            
            echo $p['file_id'];
        }
    }
146581
public function save()
    {
        /**
         * 使用PHP Sesion，Readonl，未启动 这3种情况下不需要保存
         */
        if ($this->use_php_session or !$this->isStart or $this->readonly)
        {
            return true;
        }
        //设置为Session关闭状态
        $this->isStart = false;
        $key = self::$cache_prefix . $this->sessID;
        return $this->cache->set($key, serialize($_SESSION), $this->session_lifetime);
    }
625347
public function save(): void
    {
        $keys = [];

        $primaryKey = $this->primaryKey;

        //每个行对象进行保存
        foreach ($this as $record) {
            /*
             * @var SRecord
             */
            $record->save();

            //取行对象的主键值
            $keys[] = $record->{$primaryKey};
        }

        //要删除的记录的主键值
        $deletedKeys = array_diff($this->oldPrimaryKeys, $keys);

        //一对多时,在关联表中进行删除
        if ($this->type === 'hasMany') {
            /**
             * @var $tableClass Table
             */
            $tableClass = $this->tableClass;
            $tableClass::instance()->delete([$this->primaryKey => $deletedKeys]);
        } elseif ($this->type === 'belongsToMany') {
            //多对多关联时,删除 中间表
            $config = $this->relation;

            //配置信息
            $middleClass = $config['middle'];  //中间表
            $selfForeignKey = $config['selfForeignKey'];//中间表中与本表关联的键
            $targetForeignKey = $config['targetForeignKey'];//中间表中与对方 表关联的键
            $selfPrimaryValue = $config['selfPrimaryValue']; //主表主键值

            //在中间表中进行删除
            $middleClass::instance()->delete([$selfForeignKey => $selfPrimaryValue, $targetForeignKey => $deletedKeys]);
        }
    }
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;
    }
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;
    }
1250522
public function actionSave()
    {
        $url_id = \Yii::$app->request->post('url_id');
        $menu_id = \Yii::$app->request->post('menu_id');
        $name = \Yii::$app->request->post('name');
        $alias = \Yii::$app->request->post('alias');
        $route = \Yii::$app->request->post('route');
        $method = \Yii::$app->request->post('method');
        $host = \Yii::$app->request->post('host');
        $enable_rule = \Yii::$app->request->post('enable_rule');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        if (!$alias) {
            // 自动生成别名
            if (strpos($route, '/') === 0) {
                $tempRoute = substr($route, 1, strlen($route));
            } else {
                $tempRoute = $route;
            }
            $alias = join('.', StringHelper::explode($tempRoute, '/', true, true));
        }
        $methodStr = '';
        if (is_array($method)) {
            $method = array_filter($method, function ($value) {
                return in_array($value, ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']);
            });
            $methodStr = join(',', $method);
        }
        $saveData = [
            'name' => $name,
            'alias' => $alias,
            'route' => $route,
            'method' => $methodStr,
            'host' => $host,
            'enable_rule' => $enable_rule,
            'note' => $note,
            'status' => $status,
        ];
        $obj = null;
        if ($url_id) {
            $obj = DpAdminMenuUrl::find()
                ->findByUrlId($url_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            if ($alias) {
                $obj = DpAdminMenuUrl::find()
                    ->findByAlias($alias)
                    ->one();
            }
            if (!$obj) {
                $obj = new DpAdminMenuUrl();
            }
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        if ($menu_id) {
            if (!DpAdminMenu::getByMenuId($menu_id)) {
                return $this->renderError('菜单不存在');
            } else {
                $linkObj = new DpAdminMenuUrlRelation();
                $linkObj->setAttributes([
                    'menu_id' => $menu_id,
                    'url_id' => $obj->url_id,
                    'status' => DpAdminMenuUrlRelation::STATUS_ACTIVE,
                ]);
                if (!$linkObj->save()) {
                    foreach ($obj->getErrors() as $error) {
                        foreach ($error as $message) {
                            return [
                                'success' => false,
                                'msg' => $message,
                            ];
                        }
                    }
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
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;
	}
25246
public function save()
    {
        $filepath = $this->getFilepath();
        $this->validateConfig($this->rules, $this->configData);
        $fileSystem = $this->createNew(FileSystem::class);
        $fileSystem->filePutContents($filepath, json_encode($this->configData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    }
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;
	}
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;
	}
1300786
public function save()
	{
		$result = $this->getClient()->save();
		$prodIds = array_unique( $this->getView()->param( 'product/catalog.lists.refid', [] ) );

		if( !empty( $prodIds ) )
		{
			$context = $this->getContext();
			$manager = \Aimeos\MShop::create( $context, 'product' );
			$domains = ['attribute', 'price', 'product', 'supplier', 'text'];

			$search = $manager->createSearch( true )->setSlice( count( $prodIds ) );
			$search->setConditions( $search->compare( '==', 'product.id', $prodIds ) );

			$items = $manager->searchItems( $search, $domains );
			\Aimeos\MShop::create( $context, 'index' )->rebuildIndex( $items );
		}

		return $result;
	}
202168
public function save() {
        $pk = $this->getPkField();
        //主键是id
        if (($pk == 'id' && $this->$pk) || $this->to_updata) {
            $this->update();
        } else {
            if ($this->$pk) {
                $this->checkHas();
            }
            if ($this->to_updata) {
                $this->update();
            } else {
                $this->insert();
            }
        }
    }
248660
public function save()
    {
        $result = true;

        if (!empty($this->changedData)) {
            foreach ($this->changedData as $scope => $rowData) {
                foreach ($rowData as $layoutName => $layoutData) {
                    if (empty($scope) || empty($layoutName)) {
                        continue;
                    }
                    $layoutPath = $this->getLayoutPath($scope, true);
                    $data = Json::encode($layoutData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

                    $result &= $this->getFileManager()->putContents(array($layoutPath, $layoutName.'.json'), $data);
                }
            }
        }

        if ($result == true) {
            $this->clearChanges();
        }

        return (bool) $result;
    }
88376
public function save() {

		if (empty(static::$table))
			$table = strtolower(substr(static::table(), strpos(static::table(), '\\')+1));
		else
			$table = static::$table;

		if (isset($this->_data[$table]) && count($this->_data[$table]) <= 0 ) {
			$post = $_POST;
			while(list($field, $value) = each($post)) {
				// Next if is Primary Keys
				// if (!empty($this->_id) && array_key_exists($field, $this->_id))
					// continue;
				
				$this->_data[$table][$field] = addslashes($value);
				$this->$field = $value;
			}
		}

		if ($table != '') {
			// Untuk menambah record
			if ($this->add == TRUE) {
				$before = $this->before();
				if (is_array($before) && count($before) > 1) {
					if (isset($before['insert'])) {
						$insert = $before['insert'];
						while(list($field, $value) = each($insert))
							$this->_data[$table][$field] = $value;
					}
				}
				$ret = self::$db->$table->insert($this->_data[$table]);
				$after = $this->after();
				if (is_array($after) && count($after) > 1) {
					if (isset($after['insert']) && is_callable($after['insert'])) {
						$insert = $after['insert'];
						$insert($this->_data[$table]);
					}
				}
			}
			// Untuk mengupdate record
			else {
				$before = $this->before();
				if (is_array($before) && count($before) > 1) {
					if (isset($before['update'])) {
						$update = $before['update'];
						while(list($field, $value) = each($update))
							$this->_data[$table][$field] = $value;
					}
				}
				$ret = self::$db->$table->update($this->_id, $this->_data[$table]);
				$after = $this->after();
				if (is_array($after) && count($after) > 1) {
					if (isset($after['update']) && is_callable($after['update'])) {
						$update = $after['update'];
						$update(array('pk'=>$this->_id, 'data'=>$this->_data[$table]));
					}
				}
			}
			
			$this->_data[$table] = array();
		}

		
		return $ret;
	}
768931
public function save() {

		$aUpdate =& self::$_lPoolDataChange[$this->_sConfig][$this->_mID];
		$aOrig   =& self::$_lPoolData[$this->_sConfig][$this->_mID];

		if ($aUpdate === $aOrig) {
			return FALSE;
		}

		$aOP = ($aOrig === FALSE) ? $aUpdate : self::_getDiff($aOrig, $aUpdate);

		$aOrig = $aUpdate;

		return $this->_coll()->update(
			[static::$_mKey => $this->_mID],
			$aOP,
			['upsert' => TRUE]
		);
	}