Code Monkey home page Code Monkey logo

yii2-mimin's Introduction

Yii2 Mimin

Simple RBAC Manager fo Yii 2.0. Minify of yii2-admin extension with awesome features

Latest Stable Version Total Downloads Latest Unstable Version License

Attention

Before you install and use this extension, then make sure that your application has been using the login authentication to the database. especially for yii basic template. Because without it, this extension will produce error and useless.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist agusedyc/yii2-mimin "~1.1.6"

or add

"agusedyc/yii2-mimin": "~1.1.6"

or add this for install last change

"agusedyc/yii2-mimin": "~1.*"

to the require section of your composer.json file.

Configuration

Once the extension is installed, simply use it in your code by :

in config

'as access' => [
     'class' => '\agusedyc\mimin\components\AccessControl',
	 'allowActions' => [
		// add wildcard allowed action here!
		'site/*',
		'debug/*',
		'mimin/*', // only in dev mode
	],
],
...,
'modules' => [
	'mimin' => [
		'class' => '\agusedyc\mimin\Module',
	],
	...
],
'components' => [
	'authManager' => [
		'class' => 'yii\rbac\DbManager', // only support DbManager
	],
],

Because this extension use 'yii\rbac\DbManager'as authManager, so You should migrate rbac sql first:

yii migrate --migrationPath=@yii/rbac/migrations

If You use Yii 2.0.6 version or newer, so then migrate custom table for this extension

yii migrate --migrationPath=@agusedyc/mimin/migrations

But if You install Yii 2.0.5 version or older, so then migrate custom table for this extension

yii migrate --migrationPath=@agusedyc/mimin/migrations/old

Usage

This RBAC manager have three main page, they are:

Route

To get all action route from application. In here, You can on / off permission so not shown in menu role, rename alias/type of action route, so easy readable by end user. You can then access Route through the following URL:

http://localhost/path/to/index.php?r=mimin/route

Role

To define level access of user, what he superadmin?, staff?, cashier? etc. In this menu, You can assign permission / action route (actions in application, they are create, update, delete, etc) to role. You can then access Role through the following URL:

http://localhost/path/to/index.php?r=mimin/role

Below screenshoot of route assignment to role Screenshoot Role

User

For standard user management, create/update/delete user, and assign role to user. You can then access User through the following URL:

http://localhost/path/to/index.php?r=mimin/user

We recommendate you for activate pretty URL.

Implementation on Widgets

Example dynamic button

It is used for checking if route right to access

if ((Mimin::checkRoute($this->context->id.'/create'))){
    echo Html::a('Create Note', ['create'], ['class' => 'btn btn-success']);
}

// in other case maybe You want ensure same of route so You can add parameter strict true
if ((Mimin::checkRoute($this->context->id.'/create',true))){

Example dynamic menu

It is is used for filtering right access menu

use agusedyc\mimin\components\Mimin;
$menuItems = [
    ['label' => 'Home', 'url' => ['/site/index']],
    ['label' => 'About', 'url' => ['/site/about']],
    ['label' => 'Contact', 'url' => ['/site/contact']],
];

if (\Yii::$app->user->isGuest){
    $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
}
else{
    $menuItems[] = ['label' => 'App', 'items' => [
        ['label' => 'Category', 'url' => ['/category/index']],
        ['label' => 'Product', 'url' => ['/product/index']],
        ['label' => 'Cart', 'url' => ['/cart/index']],
    ]];
    $menuItems[] = [
        'label' => 'Logout (' . \Yii::$app->user->identity->username . ')',
        'url' => ['/site/logout'],
        'linkOptions' => ['data-method' => 'post']
    ];
}

$menuItems = Mimin::filterMenu($menuItems);
// in other case maybe You want ensure same of route so You can add parameter strict true
// $menuItems = Mimin::filterMenu($menuItems,true); 

echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'items' => $menuItems,
]);

Example dynamic action column template

It is used for filtering template of Gridview Action Column

use agusedyc\mimin\components\Mimin;
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ...,
        [
          'class' => 'yii\grid\ActionColumn',
          'template' => Mimin::filterActionColumn([
              'update','delete','download'
          ],$this->context->route),
          ...
        ]
    ]
]);

How to Contribute

This tools is an OpenSource project so your contribution is very welcome.

In order to get started:

  • Install this in your local (read installation section)
  • Clone this repository.
  • Check README.md.
  • Send pull requests.

Aside from contributing via pull requests you may submit issues.

Our Team

We'd like to thank our contributors for improving this tools. Thank you!

Jakarta - Indonesia

Buku Panduan

Tutorial tentang dasar-dasar RBAC atau access controll di Yii 2 dan panduan yii2-mimin dibahas secara komprehensif di buku saya ini https://hscstudio.github.io/yii2-book-id

yii2-mimin's People

Contributors

agusedyc avatar chabibnr avatar chiliman-ooo avatar hscstudio avatar jatengstatistik avatar luckynvic avatar m-alfan avatar virbo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.