geniv / nette-identity-acl
Nette 框架的 Identity ACL 扩展
v2.1.1
2019-04-10 21:07 UTC
Requires
- php: >=7.0
- geniv/nette-general-form: >=1.0
- geniv/nette-identity-authorizator: >=1.0
- nette/application: >=2.4
- nette/utils: >=2.4
README
安装
$ composer require geniv/nette-identity-acl
或
"geniv/nette-identity-acl": "^2.1"
require
"php": ">=7.0", "nette/application": ">=2.4", "nette/utils": ">=2.4", "geniv/nette-general-form": ">=1.0", "geniv/nette-identity-authorizator": ">=1.0"
将扩展包含到应用程序中
neon 配置
#identity acl identityAcl: # autowired: true # roleFormContainer: Identity\Acl\RoleFormContainer # resourceFormContainer: Identity\Acl\ResourceFormContainer # privilegeFormContainer: Identity\Acl\PrivilegeFormContainer # aclFormContainer: Identity\Acl\AclFormContainer
如果您想通过重定义 aclFormContainer
,则必须使用 extends,例如:class UserAclFormContainer extends AclFormContainer
,并且只重定义方法:public function getForm(Form $form)
。如果您使用 AclFormContainer
类的全部内容,则将无法正常工作!
neon 配置扩展
extensions: identityAcl: Identity\Acl\Bridges\Nette\Extension
警告:在 NEON 驱动的 ACL 部分中重命名 role
、resource
和 privilege
可能会报错,因为 NEON ID 没有与自身链接。具有关系的 DIBI 驱动程序是正常的。
演示者
protected function createComponentRoleForm(RoleForm $roleForm): RoleForm { //$roleForm->setTemplatePath(path); //$roleForm->onSuccess[] = function (Form $form, array $values) { }; //$roleForm->onError[] = function (Form $form) { }; return $roleForm; } protected function createComponentResourceForm(ResourceForm $resourceForm): ResourceForm { //$resourceForm->setTemplatePath(path); //$resourceForm->onSuccess[] = function (Form $form, array $values) { }; //$resourceForm->onError[] = function (Form $form) { }; return $resourceForm; } protected function createComponentPrivilegeForm(PrivilegeForm $privilegeForm): PrivilegeForm { //$privilegeForm->setTemplatePath(path); //$privilegeForm->onSuccess[] = function (Form $form, array $values) { }; //$privilegeForm->onError[] = function (Form $form) { }; return $privilegeForm; } protected function createComponentAclForm(AclForm $aclForm, AclFormContainer $aclFormContainer, IIdentityAuthorizator $identityAuthorizator): AclForm { //$aclFormContainer->onRender = function ($data) { return $data; }; //$aclFormContainer->setMultiSelect(true); // $this['aclForm']['form']->setDefaults($this['aclForm']->getDefaults($id)); // $this['aclForm']['form']->setDefaults($identityAuthorizator->getAclForm($id)); //$aclForm->setTemplatePath(path); //$aclForm->onSuccess[] = function (Form $form, array $values) use ($aclForm) { $aclForm->saveAcl(array $values) }; //$aclForm->onError[] = function (Form $form) { }; return $aclForm; }
用法
{control roleForm} {control resourceForm} {control privilegeForm} {control aclForm}