Introducing new way for controller to view template name resolution

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Introducing new way for controller to view template name resolution

Xerkus
Per Matthew request i am starting this tread so i can get input from more people on this PR

https://github.com/zendframework/zf2/pull/5670

It introduces different way controllers are resolved to templates if no template name was provided.
In short it looks like this:
  • get controller FQCN
  • apply mapping if provided
  • strip \Controller\ namespace if present
  • strip trailing Controller in classname if present
  • inflect CamelCase to dash
  • replace namespace separator with slash

Eg: Xerkus\FooModule\Controller\Bar\FooController -> xerkus/foo-module/bar/foo/action

Goal is to support classes that do not follow PrefixModule top level namespace convention. Namely those following PSR-0 rule

<Vendor name>\(Namespace\)*<Class Name>

To maintain BC this behavior should be enabled by adding namespace to whitelist with new config option:
'view_manager' => array(
    'controller_map' => array(
        // for all controllers under my vendor namespace
        'Xerkus' => true,
        // for one of my modules, not needed with above one
        'Xerkus\FooModule' => true,
    ),
);

I'd want to see that behavior as default in zf3, if it still will be handled that way.

This PR also introduces namespace to path mapping as side effect.
-- 
Aleksey Khudyakov
ZCE, Developer at Roave LLC
http://roave.com
Reply | Threaded
Open this post in threaded view
|

Re: Introducing new way for controller to view template name resolution

EvanDotPro

Having already discussed this in depth with Aleksey, I will say that his proposal has my support. I think it is an elegant solution to one of the few remaining inflexibilities we had lurking in the MVC layer.

Thanks,
Evan

Sent from my phone. Please excuse any typos or unintentional auto-corrections.

On Jan 13, 2014 7:12 PM, "Aleksey Khudyakov" <[hidden email]> wrote:
Per Matthew request i am starting this tread so i can get input from more people on this PR

https://github.com/zendframework/zf2/pull/5670

It introduces different way controllers are resolved to templates if no template name was provided.
In short it looks like this:
  • get controller FQCN
  • apply mapping if provided
  • strip \Controller\ namespace if present
  • strip trailing Controller in classname if present
  • inflect CamelCase to dash
  • replace namespace separator with slash

Eg: Xerkus\FooModule\Controller\Bar\FooController -> xerkus/foo-module/bar/foo/action

Goal is to support classes that do not follow PrefixModule top level namespace convention. Namely those following PSR-0 rule

<Vendor name>\(Namespace\)*<Class Name>

To maintain BC this behavior should be enabled by adding namespace to whitelist with new config option:
'view_manager' => array(
    'controller_map' => array(
        // for all controllers under my vendor namespace
        'Xerkus' => true,
        // for one of my modules, not needed with above one
        'Xerkus\FooModule' => true,
    ),
);

I'd want to see that behavior as default in zf3, if it still will be handled that way.

This PR also introduces namespace to path mapping as side effect.
-- 
Aleksey Khudyakov
ZCE, Developer at Roave LLC
http://roave.com
Reply | Threaded
Open this post in threaded view
|

Re: Introducing new way for controller to view template name resolution

dolphin
This post has NOT been accepted by the mailing list yet.
Hi, I tried a few ways. Now my own strategy calculates the template path for a certain type of controllers. He run before the standard strategy (InjectTemplateListener) is executed.
But what I would like to say.
A much more efficient way, it seems to me, is the ability to specify IN CONFIGURATION OWN STRATEGY. This will be more efficient.