markdown Zend Framework 3:Controller插件管理器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Zend Framework 3:Controller插件管理器相关的知识,希望对你有一定的参考价值。

You can register controller plugins on config array
```php
return [
    'controller_plugins' => [
        'services' => [
            // Register controller plugins class instance here.
        ],
        'invokables' => [
            // Register invokable controller plugin classes here.
        ],
        'factories' => [
            // Register controller plugin factories here.
        ],
        'abstract_factories' => [
            // Register controller plugin abstract factories here.
        ],
        'aliases' => [
            // Register controller plugin aliases here.
        ],
        'shared' => [
            // Specify here which controller plugin must be non-shared.
        ]
    ]
];
```
## Available Plugin
```php
// access url plugin
$this->url();
// access params plugin
$this->params();
// access layout plugin
$this->layout();
// access identity plugin
$this->identity();
// access flash messenger plugin
$this->flashMessgener();
// access redirect plugin
$this->redirect();
// access "post redirect get" plugin
$this->postRedirectGet();
// access "file post redirect get" plugin
$this->filePostRedirectGet();
```
## Access plugin by plugin method
```php
$this->plugin(Url::class);
```
## Write your own plugin controller
```php
namespace Application\Controller\Plugin;

use Zend\Mvc\Controller\Plugin\Abstract\Plugin;

class Access extends AbstractPlugin {
    // This method checks whether user is allowed
    // to visit the page
    public function checkAccess($actionName) {
        // ...
    }
}
```
### config your own plugin controller
```php
return [
    'controller_plugins' => [
        'factories' => [
            AccessPlugin::class => InvokableFactory::classs,
        ],
        'aliases' => [
            'access' => AccessPlugin::class
        ]
    ]
];
```

以上是关于markdown Zend Framework 3:Controller插件管理器的主要内容,如果未能解决你的问题,请参考以下文章

markdown Zend Framework 3:授权和RBAC

markdown Zend Framework 3:Controller插件管理器

markdown Zend Framework 3:RBAC的访问过滤器和访问视图助手

markdown Zend Framework 3:用于身份验证服务的CurrentUser Filter和CurrentUser View Helper

如何模拟 Zend\Form 提交而不在 Zend Framework 2/3 中显示表单?

如何模拟Zend Form提交而不在Zend Framework 2/3中显示表单?