misterspelik / yii2-role-activeform
Role based ActiveForm allowing field to be editable or readoonly depending on role
Installs: 73
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.6.0
- yiisoft/yii2: >2.0.6
This package is not auto-updated.
Last update: 2024-11-18 07:53:44 UTC
README
This is a package to be used with Yii2 form widget. Usage is totally the same as Yii2 ActiveForm widget.
Installation
composer require misterspelik/yii2-role-activeform
Configuration
For example you have model User
and you want to allow edit all fields to admin
role but don't want to allow edit name field to role manager
.
For that you need to define roleRules
method with such content
public function roleRules() { return [ [ 'allow' => true, 'attributes' => ['*'], 'roles' => ['admin'] ], [ 'allow' => false, 'attributes' => ['name'], 'roles' => ['manager'] ], ]; }
Usage
To include widget to your form just use this namespace and create $form instance
use misterspelik\widgets\RoleActiveForm; $form = RoleActiveForm::begin([ 'role' => 'manager' //current user role ]); echo $form->field($model, 'name')->textInput(['maxlength' => true]); // some code here RoleActiveForm::end();