/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Concerns::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'myid' => $this->myid, 'concernid' => $this->concernid, 'created_at' => $this->created_at]); return $dataProvider; }
public function actionDelete() { $data = Yii::$app->request->post(); if (isset($data['myphone']) && isset($data['concernphone'])) { $u1 = Users::find()->where(['phone' => $data['myphone']])->one(); $u2 = Users::find()->where(['phone' => $data['concernphone']])->one(); if (!Concerns::findAll(['myid' => $u1['id'], 'concernid' => $u2['id']])) { return array('flag' => 1, 'msg' => 'is already not concern!'); } Concerns::deleteAll('myid = :myid and concernid = :concernid', [':myid' => $u1['id'], ':concernid' => $u2['id']]); $u2->concerncount--; $u2->save(); return array('flag' => 1, 'msg' => 'delete concern success!'); } else { return array('flag' => 0, 'msg' => 'arg not enough!'); } }
/** * Finds the Concerns model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Concerns the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Concerns::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }