/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Contact_category::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @return an array with id and name of categories */ public static function getContact_category() { $queryCategory = Contact_category::find()->asArray()->all(); $arrayCategory = ArrayHelper::map($queryCategory, 'id', 'name'); return $arrayCategory; }
/** * Updates an existing Contact model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $categorie = Contact_category::getContact_category(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { //$model->gruppi = $model->getGruppiContattis()->select('id_gruppo')->column(); //$model->getCheckedGroups(); return $this->render('update', ['model' => $model, 'categorie' => $categorie]); } }
/** * Finds the Contact_category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Contact_category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Contact_category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getContact_categories() { return $this->hasMany(Contact_category::className(), ['tenant_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getContact_category() { return $this->hasOne(Contact_category::className(), ['id' => 'contact_category_id']); }