/** * Updates an existing app model. * If update is successful, the browser will be redirected to the 'view' page. * * @param integer $id * @return mixed */ public function actionUpdate($id) { if (Yii::$app->session['var'] === 'admin') { $model = $this->findModel($id); //$data['kindarray'][] = '0'; //$data = array(); if ($model->load(Yii::$app->request->post())) { $dada = Yii::$app->request->post(); //$model->kind1array = $dada['app']['kind1array']; $model->kind2array = $dada['app']['kind2array']; $pics = array(); if (isset($dada['pic'])) { $pics = $dada['pic']; } //return var_dump($model); // $appofkind1 = Appofkind::find()->where(['appid'=>$id,'status'=>1])->all(); // foreach ($appofkind1 as $a){ // $a->delete(); // } $model->kind = ""; // foreach ($model->kind1array as $k) { // $model->kind = $model->kind . " " .$k; // $appofkindnew = new Appofkind(); // $appofkindnew->kind = $k; // $appofkindnew->appid = $id; // $appofkindnew->status = 1; // $appofkindnew->save(); // } $appofkind2 = Appofkind::find()->where(['appid' => $id])->all(); foreach ($appofkind2 as $a) { $a->delete(); } if (isset($dada['icon'])) { $model->icon = $dada['icon']; } if (isset($dada['android_url'])) { $model->android_url = $dada['android_url']; } foreach ($model->kind2array as $k) { $model->kind = $model->kind . " " . $k; $appofkindnew = new Appofkind(); $appofkindnew->kind = $k; $appofkindnew->appid = $id; $appofkindnew->status = 2; $appofkindnew->save(); } foreach ($pics as $pic) { $apptopicture = new Apptopicture(); $apptopicture->appid = $id; $apptopicture->picture = $pic; $apptopicture->save(); } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { $data = $model; //$kind1 = (new \yii\db\Query ())->select ('kind')->from('appofkind')->where(['appid'=>$id,'status'=>1])->all(); $kind2 = (new \yii\db\Query())->select('kind')->from('appofkind')->where(['appid' => $id])->all(); //$kind1array = array(); $kind2array = array(); // foreach ($kind1 as $index=>$kindname){ // $kind1array[]=$kindname['kind']; // } foreach ($kind2 as $index => $kindname) { $kind2array[] = $kindname['kind']; } //$data['kind1array'] = $kind1array; $data['kind2array'] = $kind2array; //$allkind1 = (new \yii\db\Query ())->select ('kind')->distinct(true)->from('appofkind')->where('status=1')->all(); $allkind2 = (new \yii\db\Query())->distinct(true)->from('tag')->where(['>', 'second', ''])->all(); //$checkbox1=array(); $checkbox2 = array(); $apptopicture = (new \yii\db\Query())->from('apptopicture')->where(['appid' => $id])->all(); // foreach($allkind1 as $name) // { // $checkbox1[$name['kind']]=$name['kind']; // } foreach ($allkind2 as $name) { $checkbox2[$name['first']][$name['second']] = $name['second']; } return $this->render('update', ['model' => $data, 'allkind2' => $checkbox2, 'apptopicture' => $apptopicture]); } } else { return $this->redirect(['login']); } }
/** * @return \yii\db\ActiveQuery */ public function getAppofkinds() { return $this->hasMany(Appofkind::className(), ['appid' => 'id']); }