Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Messages::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, 'userid' => $this->userid, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'pictures', $this->pictures]);
     return $dataProvider;
 }
 public function actionDelete()
 {
     $data = Yii::$app->request->post();
     $id = $data['messageid'];
     $msg = new Messages();
     $user = Users::findOne(['phone' => $data['phone']]);
     $msg = Messages::find()->where(['id' => $id])->one();
     if ($msg == null) {
         return array('flag' => 0, 'msg' => 'Message do not exist!');
     }
     if ($user['id'] != $msg['userid']) {
         return array('flag' => 0, 'msg' => 'you do not own the message!');
     }
     if ($msg->delete()) {
         return array('flag' => 1, 'msg' => 'Delete success!');
     } else {
         return array('flag' => 0, 'msg' => 'Delete failed!');
     }
 }