/**
  * Creates a new UserParam model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param $user_id
  * @return string|\yii\web\Response
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  */
 public function actionCreate($user_id)
 {
     $user = $this->findModel($user_id);
     $model = new UserParam();
     $model->user_id = $user->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'user_id' => $model->user_id, 'name' => $model->name]);
     } else {
         return $this->render('create', ['model' => $model, 'user' => $user]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  * @param array $params
  * @param integer $user_id
  * @return ActiveDataProvider
  */
 public function search($params, $user_id)
 {
     $query = UserParam::find()->andWhere(['user_id' => $user_id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]], 'pagination' => false]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
Beispiel #3
0
 /**
  * @param $name string
  * @param $value mixed любое приводимое к строке значение,
  * если указан null то при сохранении пользователя параметр будет удален из БД
  * @throws \yii\base\InvalidConfigException
  */
 public function setParam($name, $value)
 {
     /** @var UserParam[] $params */
     $params = $this->params;
     if (array_key_exists($name, $params) && ($p = $params[$name]) instanceof UserParam) {
         $p->value = (string) $value;
     } else {
         $params[$name] = Yii::createObject(['class' => UserParam::className(), 'user_id' => $this->id, 'name' => $name, 'value' => (string) $value]);
     }
     $this->populateRelation('params', $params);
 }