Skip to content

Commit 6bcc0ff

Browse files
committed
updated README.md
1 parent 002f6e5 commit 6bcc0ff

1 file changed

Lines changed: 11 additions & 43 deletions

File tree

README.md

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ This package contains controller like middleware to be used inside a DotKernel o
44

55
## Installation
66

7-
We use this in our web starter packages, so it will automatically be installed if you use them. For manual installation, just add the appropriate package to your `composer.json`
8-
7+
Run the following composer command in your project directory
98
```bash
109
$ composer require dotkernel/dot-controller
1110
```
12-
13-
For default module dependencies, you need to merge the ConfigProvider class output to your config. Again, if you are using the web starter packages(frontend, admin etc.), this is already handled.
14-
15-
By doing this, you "enable" the module to be available functionally for your project.
11+
Merge the `ConfigProvider` to your configuration aggregate.
1612

1713
## Usage
1814

1915
Middleware controllers act as a handler for multiple routes. Some conventions were made:
2016
- register controllers in the routes array just like any expressive middleware. The requirement is that you should define an `action` route parameter(possibly optional) anywhere inside the route(e.g `/user[/{action}]`)
21-
- action parameter value is converted to a method name inside the controller. Underscore, dot and line characters are removed and the action name is converted to camel-case suffixed by the string `Action`. For example a route and action pair like `/user/forgot-password` will be converted to method `forgotPasswordAction` inside a `UserController` class(as defined in routes config)
17+
- action parameter value is converted to a method name inside the controller. Underscore, dot and line characters are removed and the action name is converted to camel-case suffixed by the string `Action`. For example a route and action pair like `/user/forgot-password` will be converted to method `forgotPasswordAction`.
2218
- the default action value, if not present in the URI is `index`, so you should always define an `indexAction` within your controllers for displaying a default page or redirecting.
2319

2420
In order to create your action based controllers, you must extend the abstract class `DotKernel\DotController\AbstractActionController`
@@ -45,53 +41,24 @@ class UserController extends AbstractActionController
4541
}
4642
```
4743

48-
Then register this controller in the `routes` config(we assume you use FastRouter and ZF3 service manager)
49-
##### routes.global.php
50-
```php
51-
'dependencies' => [
52-
//add UserController class as a dependency, in invokable or factories etc.
53-
//for example
54-
'factories' => [
55-
\Your\Namespace\UserContoller::class => \Your\Namespace\UserContollerFactory::class,
56-
]
57-
],
58-
59-
'routes' => [
60-
[
61-
'name' => 'user',
62-
'path' => '/user[/{action}]',
63-
'middleware' => Your\Namespace\UserController::class,
64-
]
65-
],
66-
```
44+
Then register this controller as a routed middleware in file `routes.php` just like a regular middleware.
6745

6846
### Multiple controllers for the same route
6947

7048
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
7149
- create your own controller, independent of the package's controller which adds more actions
72-
- ZE lets you define an array of middleware for a route, so you can register this controller before the package's controller
50+
- Zend Expressive lets you define an array of middleware for a route, so you can register this controller before the package's controller
7351

74-
##### Example
75-
```php
76-
'routes' => [
77-
[
78-
'name' => 'user',
79-
'path' => '/user[/{action}]',
80-
'middleware' => [Your\Namespace\UserController::class, Package\UserController::class],
81-
]
82-
]
83-
```
84-
85-
Now when a request for this route comes in, your controller will run first. Dot 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.
86-
If this is the last controller, and action does not match here, it will go to the default 404 Not found page. There is a simple middleware defined in dot-helpers that makes sure any request that does not match will be converted explicitly to a 404 error.
52+
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.
53+
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)
8754

8855
## Controller plugins
8956

9057
Controllers support controller plugins, much like controllers in a ZF3 application. The module comes packed with a few common plugins, but you can extend controller functionality with your own plugins too.
9158

9259
### Usage
9360

94-
Controller plugins must implement `DotKernel\DotController\Plugin\PluginInterface`. You can add them to the config file, at key `['dk_controller']['plugin_manager']`. The design pattern uses the `AbstractPluginManager` provided by ZF3 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`.
61+
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 ZF3 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`.
9562

9663
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)
9764

@@ -112,6 +79,7 @@ Although these are optional, if a package is missing, the controller will not ha
11279
- `template` wraps TemplateInterface provided by ZE, to make template engine accessible to any controller
11380
- `url` wraps the UrlHelper class provided by ZE helpers package. Used to generate URIs from routes
11481

115-
### Writing custom controller plugins
11682

117-
//@TODO: write documentation
83+
## Controller Events
84+
85+
// @TODO

0 commit comments

Comments
 (0)