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

Commit 26458c9

Browse files
committed
Merge branch 'hotfix/155'
Close #155
2 parents 7d1104a + 14d26fa commit 26458c9

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,21 @@ 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__` was not present. This caused issues when multiple modules shared
422+
a top-level namespace (e.g., `ZF\Apigility` and `ZF\Apigility\Admin`) and 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

428-
- Strip the `Controller` subnamespace, if present (e.g.,
429-
the namespace `Application\Controller\\` is normalized to
430-
`Application\\`).
428+
- Strip the `Controller` subnamespace, if present (e.g., the namespace
429+
`Application\Controller\\` is normalized to `Application\\`).
431430
- Strip the `Controller` suffix in the class name, if present (e.g.,
432431
`IndexController` is normalized to `Index`).
433432
- Inflect CamelCasing to dash-separated (e.g., `ShowUsers` becomes
@@ -439,6 +438,9 @@ As a full example, the controller service name
439438
`test-something/with/camel-case`, regardless of the `__NAMESPACE__` value
440439
provided in routing configuration.
441440

441+
If needed, you can emulate the version 2 behavior in version 3 via namespace
442+
whitelisting in the controller <=> template map.
443+
442444
## Zend\Mvc\View\SendResponseListener
443445

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

doc/book/quick-start.md

Lines changed: 11 additions & 19 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,33 +177,25 @@ 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, the default template name resolver uses fully qualified
182+
controller class names, stripping only the `\Controller\\` subnamespace, if
183+
present. For example, `AwesomeMe\MyModule\Controller\HelloWorldController`
184+
resolves to the template name `awesome-me/my-module/hello-world` via the
185+
following configuration:
187186

188187
```php
189188
'view_manager' => array(
190-
// Controller namespace to template map
191-
// or whitelisting for controller FQCN to template mapping
192189
'controller_map' => array(
193-
'<Module\Name>' => true,
190+
'AwesomeMe\MyModule' => true,
194191
),
195192
),
196193
```
197194

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-
```
195+
(In v2 releases, the default was to strip subnamespaces, but optional mapping rules
196+
allowed whitelisting namespaces in module configuration to enable current
197+
resolver behavior. See the [migration guide](migration/to-v3-0.md#zendmvcviewinjecttemplatelistener)
198+
for more details.)
207199

208200
## Create a Route
209201

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)