/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search() { $query = GlobalConfigModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!$this->validate()) { $query->where('1=0'); return $dataProvider; } $query->andFilterWhere(['group' => $this->group]); return $dataProvider; }
/** * Finds the GlobalConfig model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $group * @param string $name * @return GlobalConfig the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($group, $name) { if (($model = GlobalConfig::findOne(['group' => $group, 'name' => $name])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @inheritdoc */ public function beforeSave($insert) { if (parent::beforeSave($insert)) { $this->raw_value = serialize($this->_values); return true; } return false; } /** * @inheritdoc */ public function afterFind() { $this->_schema = static::$schemaDefinition[$this->group]; $this->_values = unserialize($this->raw_value); parent::afterFind(); } /** * @inheritdoc */ public function behaviors() { return [['class' => 'yii\\behaviors\\TimestampBehavior', 'value' => new \yii\db\Expression('NOW()')], 'yii\\behaviors\\BlameableBehavior']; } } // GlobalConfig::$schemaDefinition = (require __DIR__ . '/schema_definition.php');