Download the PHP package jlorente/yii2-roles without Composer

On this page you can find all versions of the php package jlorente/yii2-roles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-roles

Yii2 Roles

A Yii2 extension that includes the concept of roles in the framework. Useful to handle user access to controllers actions allowed only for some roles and filter database resources.

The role storage design is optimized to use a single database field following the data structure of a "bit field" or "flag" that can hold a large number of roles and all the possible combinations of them occupying the space of a integer.

Installation

Include the package as dependency under the composer.json file.

To install, either run

or add

to the section of your composer.json file and run the following commands from your project directory.

Migration

Apply the package migration

or extend this migration in your project and apply it as usually.

You can override the roleableTableName() and the roleFieldName() methods in order to provide another table and field names to hold the role value.

Module setup

You must add this module to the module section and the bootstrap section of the application config file in order to make it work.

../your_app/config/main.php

Options

user

The user parameter force the application to use the web User class included in the module that allows the authentication of user sessions with differents roles. That means for example that a user that owns two roles can access the application with only one of them active.

This is useful when you are building an application with frontend and backend sections and you don't want to share the login between them.

roles

The roles array can contain any scalar values, but they must be unique along the collection.

This returned values represent your roles values. The internal values of the Roleable are set depending on the order of the collection following the rules of a flag field. So [role0, role1, role2, ..., roleN] will become [1, 2, 4, ..., (1 << N)]

You can add new roles at the end of the array and nothing created earlier will be affected, but be aware that changing the order of the collection after having used it will cause that previous assigned roles will have now other values, so don't change the order of the roles once set and used.

matchAgainstSession

If this param is set to true, you will have to specify the roles that the web user will own on login. The access rules of the controller actions will match against the roles assigned to the web user instead of the roles of the identity model.

Usage

The Roleable class

The ActiveRecord class that owns the role attribute (usually table user and class User) MUST implement the RoleableInterface.

With the package comes a RoleableTrait that can be used in the class that implements this interface in order to add a basic implementation of the required methods.

For example:

./common/models/User.php

Assigning roles to the Roleable

You can easyly add roles to a Roleable object using the Role class.

Following the last example

Controller access control

You can filter the access to the controller actions by using the AccessControl class of the module.

./frontend/controllers/SomeController.php

Specifiying the "userRoles" attribute you can define what roles are allowed to access the actions.

As you can see in the above example, yo can override the matchAgainstSession attribute defined in the Module class for a single rule.

Matching the controller access against the session

As told before, setting the matchAgainstSession attribute to true implies that the session data must store the logged role.

This is done by setting the role of the web user just before login it in.

Not setting the role manually will cause the session to be logged with all the roles owned by the identity model.

Further considerations

It is a good practice to define the roles as constants to avoid misspelling the roles tags.

./your_app/config/main.php

And then use this constants to configure the module, assign roles to users, defining access rules, etc...

License

Copyright © 2016 José Lorente Martín [email protected].

Licensed under the MIT license. See LICENSE.txt for details.


All versions of yii2-roles with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jlorente/yii2-roles contains the following files

Loading the files please wait ....