public function init() { parent::init(); $this->_texts = Data::cache(TextModel::CACHE_KEY, 3600, function () { $models = TextModel::find()->where(['status' => TextModel::STATUS_PUBLISHED])->all(); $return = []; foreach ($models as $k => $model) { $return[$model->slug . '_' . \Yii::$app->language][$model->id] = $model; } return $return; }); }
public function setAttributesByPost($postData = array()) { $postData = Yii::app()->getRequest()->getPost($this->_getPostKey()); if ($postData) { $this->items->clear(); foreach ($postData as $n => $data) { $item = $this->createItem(); $item->setAttributes(DataHelper::trimRecursive($data)); // Важно сохранить номер, чтобы правильно сработала ajax валидация $this->items[$n] = $item; } } }
/** * Update the specified resource in storage. * * @param UserRequest|Request $request * @param $id * @return \Illuminate\Http\Response */ public function update(UserRequest $request, $id) { $data = $request->all(); Data::checkIsSet($data, 'confirm'); if (Hash::check($data['confirm'], auth()->user()->getAuthPassword())) { // todo: flash success $user = \App\User::find($id); $user->update($data); return redirect()->route('admin.user.index'); } dd(auth()->user()->getAuthPassword()); // todo: flash wrong password return redirect()->route('admin.user.edit')->withInput($data); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $node_id) { $data = $request->all(); $rules = $this->provider->rules($data['module']); $validator = Validator::make($data, $rules); //TODO if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $data = Data::checkActive($data); $data = Data::renameField($data, 'module', 'module_id'); // dd($data); // Create Module $module = $this->provider->store($data); $data = Data::addField($data, 'row', $module['id']); //Create Element $element = \App\Element::create($data); $element->save(); $data = Data::addField($data, 'node_id', $node_id); $data = Data::addField($data, 'element_id', $element->id); $content = \App\Content::create($data)->save(); //todo: flash message return redirect()->route('admin.element.index', ['node' => $node_id]); }
public function setAttribute($name, $value) { parent::setAttribute(DataHelper::camelToSnake($name), $value); }
/** * @param string $code */ public static function change($code) { Data::save('currency', $code); }
public function fixCssName($name) { return strtr(DataHelper::camelToSnake($name), '_', '-'); }
public function setAttributesByPost($postData = array()) { $postKey = CHtml::modelName($this); $postData = $postData ?: $_POST; $data = array(); if (!empty($postData[$postKey])) { $data = $postData[$postKey]; } $this->setAttributes(DataHelper::trimRecursive($data)); }
/** * Saves wish list */ public function save() { Data::save('wish_list', $this); }
/** * @return Country[] */ public function api_countries() { return Data::cache($this->makeCacheKey(), function () { return Country::find()->all(); }); }
/** * Saves order address */ public function save() { Data::save('order_address', $this); }
/** * Saves cart */ public function save() { Data::save('shopping_cart', $this); }