/** * 根据一个或多个角色id获取角色名字 * @author sunzheng */ public static function getRoleNamesByIds($ids) { $arr = explode(',', $ids); $searchIds = []; foreach ($arr as $v) { if (is_numeric($v)) { $searchIds[] = $v; } } $data = array(); if ($searchIds) { $results = RbacRole::find()->select(['role_id', 'role_name'])->asArray()->where('role_id in (' . implode(',', $searchIds) . ')')->orderBy('role_id ASC')->all(); foreach ($results as $v) { $data[$v['role_id']] = $v['role_name']; } } return $data; }
public function getRoleModel() { return $this->hasOne(RbacRole::className(), ['role_id' => 'role_id'])->onCondition('rbac_role.role_id is not null'); }
/** * 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\RbacRole::findOne($id)) !== null) { return $model; } else { throw new Exception('The requested page does not exist.'); } }