/** * 授权任务给角色 * @author lixupeng * @param type $id * @throws Exception */ public function actionAssignItems($id) { $model = self::findModel($id); $items = Yii::$app->request->post('authItems'); if (!is_array($items)) { throw new Exception('Invalid request.Params has Error. Please do not repeat this request again.'); } // 安全过滤待授权的项目 $authItems = models\RbacAuthtask::getAllTask(); $authItemsKeys = array_keys($authItems); $items = array_intersect($items, $authItemsKeys); if ($items && models\RbacRoleTask::assignTaskToRole($id, $items)) { echo '授权成功'; } else { throw new Exception('授权失败'); } }
/** * Finds the Country model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Country the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = models\RbacAuthtask::findOne($id)) !== null) { return $model; } else { throw new Exception('The requested page does not exist.'); } }
public function getAuthtask() { return $this->hasOne(RbacAuthtask::className(), ['task_id' => 'task_id']); }