yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Yii2 RBAC with MongoDB #2541

Closed z010107 closed 8 years ago

z010107 commented 10 years ago

Hello everyone. I have one project where I use MongoDB. Current version RBAC is not support Mongo DbManager. That is why I make MongoDbManager.php.

Code here: https://github.com/z010107/yii2_rbac_mongodb Usage:

Put this class into /framework/rbac/MongoDbManager.php And change config

$config = [
    ...
    'components' => [
        ...
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://localhost:27017/dbname',
        ],

        'authManager' => [
            'class' => 'yii\rbac\MongoDbManager',
            'defaultRoles' => ['guest'],
        ],
        ...
    ],
    ...
];
cebe commented 10 years ago

There are plans to port RBAC classes to be active records. this would allow using them on different noSQL dbms.

zbitname commented 10 years ago

It would be nice

indicalabs commented 10 years ago

I think we may need to add a schema-mongo.sql table under yii2/rbac to create auth tables. Does the current rbac implementation works for mongo?

lav45 commented 10 years ago

yii2\rbac\DbManager generate SQL query to the database

...
        $query = new Query; // <== is query builder
        $parents = $query->select(['parent'])
            ->from($this->itemChildTable)
            ->where(['child' => $itemName])
            ->column($this->db);
...

to support noSQL databases, you must use ActiveRecord

        $parents = AuthItemChild::find()
            ->select(['parent'])
            ->where(['child' => $itemName])
            ->column($this->db);
klimov-paul commented 8 years ago

Resolved by https://github.com/yiisoft/yii2-mongodb/pull/110