/** * Creates a new RoleMaster model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id) { $model = new RoleMaster(); if ($model->load(Yii::$app->request->post())) { if (isset(Yii::$app->request->post()['RoleMaster']['action']) && !empty(Yii::$app->request->post()['RoleMaster']['action'])) { $user_typeid = $model->user_type_id; RoleMaster::deleteAll('user_type_id = :user_type_id', [':user_type_id' => $user_typeid]); foreach (Yii::$app->request->post()['RoleMaster']['action'] as $action) { $model = new RoleMaster(); $model->user_type_id = $user_typeid; $model->role_action_id = $action; $model->save(); } } return $this->redirect(['usertype/index']); } else { $tree_view = $this->getTreeModuleView($id); $model->user_type_id = $id; return $this->render('create', ['model' => $model, 'tree_view' => $tree_view]); } }