示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Replys::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, 'messageid' => $this->messageid, 'fromid' => $this->fromid, 'toid' => $this->toid, 'isread' => $this->isread, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
 public function actionReply()
 {
     $data = Yii::$app->request->post();
     //$user=new Users();
     $fromphone = Users::find()->select('id')->where(['phone' => $data['fphone']])->one();
     //var_dump($fromphone);
     $model = new Replys();
     if ($data['tphone'] == '') {
         $model->toid = 0;
     } else {
         $tophone = Users::find()->select('id')->where(['phone' => $data['tphone']])->one();
         //var_dump($tophone);
         $model->toid = $tophone['id'];
     }
     // 		$to=Messages::findOne(['id'=>$data['msgid']]);
     // 		if($fromphone['id']!=$to['id']){
     // 			$model3=new Notify();
     // 			$model3->from=$fromphone['id'];
     // 			$model3->to=$to['userid'];
     // 			//$model3->kind='评论';
     // 			$model3->kind=$data['content'];
     // 			$model3->created_at=time();
     // 			$model3->msg_id=$data['msgid'];
     // 			if(!$model3->save()){
     // 				echo json_encode ( array (
     // 						'flag' => 0,
     // 						'msg' => 'Reply failed!'
     // 				));
     // 				return;
     // 			}
     // 		}
     $model->fromid = $fromphone['id'];
     $model->messageid = $data['messageid'];
     $model->content = $data['content'];
     $model->isread = 0;
     $model->created_at = time();
     //var_dump($model);
     if ($model->save()) {
         return array('flag' => 1, 'msg' => 'Reply success!');
     } else {
         return array('flag' => 0, 'msg' => 'Reply failed!');
     }
 }
示例#3
0
 /**
  * Finds the Replys model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Replys the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Replys::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }