/** * 授权任务给角色 * @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('授权失败'); } }