Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 08f5593

Browse files
committed
Merge pull request #155 from Xerkus/fix-docs
Update docs to reflect template map resolver change in v3
2 parents 7d1104a + 157d3e1 commit 08f5593

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

doc/book/migration/to-v3-0.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,22 @@ the section above on [dependency reduction](#dependency-reduction).
412412

413413
## Zend\Mvc\View\InjectTemplateListener
414414

415-
The `InjectTemplateListener` attempts to map a controller *service* name to a
415+
The `InjectTemplateListener` attempts to map a controller name to a
416416
template using a variety of heuristics, including an explicit map provided
417-
during configuration, or auto-detection based on the service name.
417+
during configuration, or auto-detection based on the controller class name.
418418

419419
In version 2, the autodetection took into consideration the `__NAMESPACE__`
420-
provided in routing configuration, and would omit the module subnamespace if a
421-
match was found. This caused issues when multiple modules shared a top-level
422-
namespace (e.g., `ZF\Apigility` and `ZF\Apigility\Admin`) if each had a
423-
controller with the same name.
420+
route match parameter to derive subnamespaces or would omit them completely if
421+
`__NAMESPACE__` is not present. This caused issues when multiple modules shared
422+
a top-level namespace (e.g., `ZF\Apigility` and `ZF\Apigility\Admin`) if each
423+
had a controller with the same name.
424424

425425
To avoid naming conflicts, version 3 removes this aspect of autodetection, and
426426
instead provides exactly one workflow for mapping:
427427

428428
- Strip the `Controller` subnamespace, if present (e.g.,
429-
the namespace `Application\Controller\\` is normalized to
430-
`Application\\`).
429+
the namespace `Application\Controller\` is normalized to
430+
`Application\`).
431431
- Strip the `Controller` suffix in the class name, if present (e.g.,
432432
`IndexController` is normalized to `Index`).
433433
- Inflect CamelCasing to dash-separated (e.g., `ShowUsers` becomes
@@ -439,6 +439,9 @@ As a full example, the controller service name
439439
`test-something/with/camel-case`, regardless of the `__NAMESPACE__` value
440440
provided in routing configuration.
441441

442+
Similar behavior in version 2 could be achieved with namespace whitelisting in
443+
controller to template map
444+
442445
## Zend\Mvc\View\SendResponseListener
443446

444447
`Zend\Mvc\View\SendResponseListener` was deprecated with the 2.2 release, and

doc/book/quick-start.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ So, what are we doing here?
146146

147147
We return a `ViewModel`. The view layer will use this when rendering the view,
148148
pulling variables and the template name from it. By default, you can omit the
149-
template name, and it will resolve to "lowercase-controller-name/lowercase-action-name".
149+
template name, and it will resolve to "lowercase-module-name/lowercase-controller-name/lowercase-action-name".
150150
However, you can override this to specify something different by calling
151151
`setTemplate()` on the `ViewModel` instance. Typically, templates will resolve
152152
to files with a ".phtml" suffix in your module's `view` directory.
@@ -177,34 +177,24 @@ That's it. Save the file.
177177
## View scripts for module names with subnamespaces
178178

179179
As per PSR-0, modules should be named following the rule: `<Vendor Name>\<Namespace>\*`.
180-
However, the default controller class to template mapping does not work very
181-
well with those: it will remove subnamespace.
182180

183-
To address that issue, new mapping rules were introduced with version 2.3.0. To
184-
maintain backwards compatibility, that mapping is not enabled by default. To
185-
enable it, you need to add your module namespace to a whitelist in your module
186-
configuration:
181+
Since version 3.0 default template name resolver uses fully qualified controller
182+
class name, stripping only `\Controller\` subnamespace, if present.
183+
For example, `AwesomeMe\MyModule\Controller\HelloWorldController` is resolved
184+
to template name `awesome-me/my-module/hello-world`.
185+
186+
For prior versions default was to strip subnamespaces but optional mapping rules
187+
allowed to whitelist namespaces in module configuration to enable current
188+
resolver behavior:
187189

188190
```php
189191
'view_manager' => array(
190-
// Controller namespace to template map
191-
// or whitelisting for controller FQCN to template mapping
192192
'controller_map' => array(
193-
'<Module\Name>' => true,
193+
'<AwesomeMe\MyModule>' => true,
194194
),
195195
),
196196
```
197197

198-
Once you have, you can create the directory `view/<module>/<name>/hello`. Inside
199-
that directory, create a file named `world.phtml`. Inside that, paste the
200-
following:
201-
202-
```php
203-
<h1>Greetings!</h1>
204-
205-
<p>You said "<?php echo $this->escapeHtml($message) ?>".</p>
206-
```
207-
208198
## Create a Route
209199

210200
Now that we have a controller and a view script, we need to create a route to it.

doc/book/services.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ return [
753753
'default_template_suffix' => $templateSuffix, // e.g. 'php'
754754

755755
// Controller namespace to template map
756-
// or whitelisting for controller FQCN to template mapping
757756
'controller_map' => [
758757
],
759758

0 commit comments

Comments
 (0)