@@ -146,7 +146,7 @@ So, what are we doing here?
146
146
147
147
We return a ` ViewModel ` . The view layer will use this when rendering the view,
148
148
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".
150
150
However, you can override this to specify something different by calling
151
151
` setTemplate() ` on the ` ViewModel ` instance. Typically, templates will resolve
152
152
to files with a ".phtml" suffix in your module's ` view ` directory.
@@ -177,33 +177,25 @@ That's it. Save the file.
177
177
## View scripts for module names with subnamespaces
178
178
179
179
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.
182
180
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:
187
186
188
187
``` php
189
188
'view_manager' => array(
190
- // Controller namespace to template map
191
- // or whitelisting for controller FQCN to template mapping
192
189
'controller_map' => array(
193
- '< Module \Name > ' => true,
190
+ 'AwesomeMe\MyModule ' => true,
194
191
),
195
192
),
196
193
```
197
194
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.)
207
199
208
200
## Create a Route
209
201
0 commit comments