You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package contains controller like middleware to be used inside a DotKernel or Mezzio application. It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins.
3
+
This is DotKernel's controller package that can be use like middleware inside DotKernel or Mezzio application.
4
+
It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins and event listeners
Use case: You have defined a controller inside some package, with default actions. You want to add actions that fall into the same controller name(or route name more exactly). You want to do this without extending the controller provided by the package. In this case you can do the following
62
72
- create your own controller, independent of the package's controller which adds more actions
63
73
- Mezzio lets you define an array of middleware for a route, so you can register this controller before the package's controller
64
74
65
-
Now when a request for this route comes in, your controller will run first. DotKernel controllers are designed to ignore requests that cannot be matched to one of its methods, so if no action matches, it will call the next middleware, in our case, the second controller.
75
+
Now when a request for this route comes in, your controller will run first. DotKernel controllers are designed to ignore requests that cannot be matched to one of its methods, so if no action matches, it will call the next middleware, in our case, the second controller.
66
76
If this is the last controller, and action does not match here, it will go to the default 404 Not found page(handled by NotFoundDelegate)
67
-
68
-
## Controller plugins
69
-
70
-
Controllers support controller plugins, much like controllers in a Laminas application. The module comes packed with a few common plugins, but you can extend controller functionality with your own plugins too.
71
-
72
-
### Usage
73
-
74
-
Controller plugins must implement `Dot\Controller\Plugin\PluginInterface`. You can add them to the config file, at key `['dk_controller']['plugin_manager']`. The design pattern uses the `AbstractPluginManager` provided by Laminas service manager component. So, registration of a plugin under the aforementioned config key looks the same as the declaration of regular dependencies, as `AbstractPluginManager` actually extends `ServiceManager`.
75
-
76
-
Once registered, a plugin can be directly accessed in any controller, by calling a method with the plugin's name(the service name or the key at which the plugin is registered inside the manager)
77
-
78
-
Controller plugins offer the advantage of globally accessible functionality in any controller without to manually inject dependencies. Plugins should be used for functions that are common to any controller. Do not clutter controller's code with unnecessary plugins.
79
-
80
-
##### Example
81
-
```php
82
-
//inside a controller
83
-
//assume we've already registered a plugin called testPlugin
84
-
$this->testPlugin(); //will return the TestPlugin class so you can call any public defined method on it
85
-
$this->testPlugin()->someMethod();
86
-
```
87
-
88
-
### Built-in plugins
89
-
Note: Each of these plugins requires the associated Mezzio packages to be installed and available in your project.
90
-
Although these are optional, if a package is missing, the controller will not have the associated functionality available
91
-
92
-
-`template` wraps TemplateInterface provided by Mezzio, to make template engine accessible to any controller
93
-
-`url` wraps the UrlHelper class provided by Laminas helpers package. Used to generate URIs from routes
After installation, the package can be used immediately but if you want to use all features of the package, like plugins and events you need to register the `ConfigProvider` in your project by adding the below line to your configuration aggregator (usually: `config/config.php`):
0 commit comments