Comments (2)
Hi,
I'm not sure... It doesn't make much sense (from the OOP point of view)... what you might mean is "getRoles()",... and also, it doesn't make sense to have and "$id" param in that function... because the class instance IS the user itself.
So for this case, I agree having only one function called "getRoles" which returns an array containing all the permissions/roles for the active user (no $id param).
Regarding the function getRoleArray() looks fine, however, the array-to-string conversion should be work for the developer, because not all the developers need to format the resulting array into a comma separated string, you might want to format it using your own style. So, in that case, the "getRoles" functions is enough.
IMHO The other functions need some review. I'm not so sure of having the "setRoles" function, because you might want to append a single permission, and every time you want to add/remove a permission, the DB processing will be slow (because it will rewrite all the permissions again).
from yii2-auth.
Do you have any suggestion to add the role without SetRole function to database ?? How can we do this with a simple way ?? Because model->save is not work, when I tried it gives me error .. I think we should done this with a seperate function ...
And yes the id is useless, I have forgot it there because I have tested something else, the function actually like this ..
public function getRole()
{
/** @var \yii\rbac\DbManager $authManager */
$authManager = Yii::$app->get('authManager');
$Ridentity = $authManager->getRolesByUser($this->id);
if($Ridentity)
{
foreach ($Ridentity as $item)
{
$role[$item->name] = $item->name;
}
}
else
{
$role=null;
}
return $role;
}
We need getRoleTypes function too, because there is no role when we create a user, and to be selected and attached to a user we need to return the role types from the database...
public function getRoleTypes()
{
/** @var \yii\rbac\DbManager $authManager */
$roller = Yii::$app->get('authManager')->getRoles();
foreach ($roller as $item)
{
$role[$item->name] = $item->name;
}
return $role;
}
from yii2-auth.
Related Issues (20)
- problem on install composer HOT 10
- Exception 'yii\db\Exception' with message 'could not find driver' HOT 5
- Calling unknown method: yii\web\User::getIsSuperAdmin() HOT 3
- "User" instead of "user" name table when running db migration at install HOT 3
- Forbidden (#403) when try access to /auth/user/index HOT 1
- Unable to install HOT 4
- install failed HOT 4
- migration errors HOT 3
- override controller HOT 2
- Cannot open index, got invalid table name HOT 1
- Really need RBAC HOT 2
- Change NotSupportedException on yii\base\NotSupportedException in models/User.php HOT 1
- fuckup in migrations/m000000_000002_CreateUserTables.php HOT 1
- Logout Error Unable to verify your data submission.
- you should configure authmanager component to use database before executing this migration
- Time Zones
- $ php yii migrate/up --migrationPath=@auth/migrations Error: Unknown command "migrate\up".
- Profile status update
- Not hashing password when creating user from admin view
- No existen mensajes en español en vista de registro "sign up" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-auth.