示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Usertocards::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]);
     $query->andFilterWhere(['like', 'cardnumber', $this->cardnumber]);
     return $dataProvider;
 }
 public function actionDelete()
 {
     $data = Yii::$app->request->post();
     if (empty($data['phone']) || empty('usertocardid')) {
         return array('flag' => 0, 'msg' => 'no enough arg!');
     }
     $user = Users::findOne(['phone' => $data['phone']]);
     if (!$user) {
         return array('flag' => 0, 'msg' => 'user not exist!');
     }
     $model = Usertocards::findOne(['id' => $data['usertocardid']]);
     if (!$model) {
         return array('flag' => 0, 'msg' => 'usertocard not exist!');
     }
     if ($model['userid'] != $user['id']) {
         return array('flag' => 0, 'msg' => 'not the owner!');
     }
     if ($model->delete()) {
         return array('flag' => 1, 'msg' => 'delete success!');
     } else {
         return array('flag' => 0, 'msg' => 'delete failure!');
     }
 }
 /**
  * Finds the Usertocards model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Usertocards the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Usertocards::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#4
0
 public function getUsertocards()
 {
     return $this->hasMany(Usertocards::className(), ['userid' => 'id']);
 }