ceadreak
ceadreak

Reputation: 1684

ZF2 / use 2 differents view helpers with the same name

In a ZF2 modular application, I have 2 differents view helpers with the same name in 2 differents modules.

I want to use one in the first module, and the other one in the second module.

In the first module configuration file, I have a view_helpers config key with my view helpers definitions.

view_helpers => [
    myCustomViewHelper => myCustomViewHelper::class
]

In the second one, I have a my_module_view_helpers config key ...

my_module_view_helpers => [
    myCustomViewHelper => myCustomViewHelper2::class
]

What I want to do, is to erase the first one by the second one for the second module.

How is it possible to achieve that ?

Upvotes: 0

Views: 62

Answers (1)

Saeven
Saeven

Reputation: 2300

I understood that Module load order determines which gets actually registered. If you load your custom module last, it should become the defacto helper with that name.

Make sure to use the right keys in both module configs.

'view_helpers' => [
    'invokables' => [
        'thatHelper' => ThatHelper::class,
    ],
    'factories' => [
        'otherHelper' => ThatOtherHelper::class,
    ]
]

What you'll run into though, is any program reference to that helper in 'other' modules will also use yours. Unless that's the intention, that could cause a world of hurt. My advice, give it a new name. ;) It's just a name! :D

Upvotes: 1

Related Questions