widmogrod / zf2-assetic-module

Zend Framework module for Assetic
146 stars 62 forks source link

Deprecate injection of assets based on controller/action. #98

Open Thinkscape opened 11 years ago

Thinkscape commented 11 years ago

At first, I was happy and keen to rely on automatic injection of assets depending on the controller/action. However after some time using it, I've found it's prone to a lot of errors.

Because of the nature of zf2 mvc and modules interacting with the request flow, the injection is very fragile. For example, errors will cause the request to be handled by error controller, however the mod has already decided to use assets from the non-existent page. Another example would be any access-control modules, which deny access or forward depending on some conditions - this also confuses the mod.

The only safe way to handle this is to rely on explicit inclusion of resources. Because resources belong to the rendering/view phase, they should live there - so the perfect place would be a view helper, or resolver attached to a view helper. In any case, the inclusion must happen at rendering/view phase, not dispatch.

There's also the case of flexibility - current "matchers" only work on controller and action names. It is not possible to branch the inclusion logic inside controller and/or view script. If we had explicit inclusion then one could include any resources based on any requirements (be that in controller, layout, page view script or some listener).

widmogrod commented 11 years ago

Very good point. If you create pull request with such changes I will merge it. But very important is to maintain back compatibility.