request->post(); $model = new UserRn(); $model->load($input,''); $model->nid = $input['nid']; if(!$model->validate()) return $model->errors; $model->deleteAll(['rid'=>$model->rid,'type'=>$model->type]); foreach ($model->nid as $val) { $_model = clone $model; $_model->rid = $model->rid; $_model->nid = $val; $_model->type = $model->type; $_model->create_at = $_SERVER['REQUEST_TIME']; $_model->insert(); } return true; } public function CreateUserRole() { $model = new UserUr(); $model->load(Yii::$app->request->post('data'),''); $model->rid = Yii::$app->request->post('data')['rid']; if(!$model->validate()) return $model->errors; $model->deleteAll(['uid'=>$model->uid]); foreach ($model->rid as $val) { $model->isNewRecord = true; $model->rid = $val; $model->create_at = $_SERVER['REQUEST_TIME']; $model->insert(); } return true; } }