Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Zan::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     //$value = 0;
     if ($params != false && !empty($params['ZanSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['ZanSearch'] as $name => $value1) {
             if ($name === 'myid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['ZanSearch']['myid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
         }
     }
     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(['myid' => $this->value, 'msgid' => $this->msgid]);
     return $dataProvider;
 }
 public function actionCancelZan()
 {
     $data = Yii::$app->request->post();
     $user = new User();
     $phone = $user->find()->select('id')->where(['phone' => $data['phone']])->one();
     $info = Zan::findOne(['myid' => $phone['id'], 'msgid' => $data['msgid']]);
     if ($info) {
         $info->delete();
         echo json_encode(array('flag' => 1, 'msg' => 'Cancel success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Cancel failed!'));
     }
 }
 /**
  * Finds the Zan model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Zan the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Zan::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }