Publishing assets from modules in Zend Framework 2

2019-04-01 02:45发布

It is generally adviced to store module assets inside the module's directory, inside moduleName/public (or whatever you want to name the asset's directory).

Zend Framework 2 unfortunately doesn't support asset publishing for module assets by default. According to MWOP, there was nothing planned ~1 month ago and I guess there still is no real plan (they had probably a lot of work to get the stable version ready). (But, some day, they are going to address this issue.)

As my ZF2 app is growing and growing, I reached the point where I need to have module-specific assets. At the moment, I maintain them inside the module directories and copy them to the application's public directory. You can imagine that this method is error-prone and exhausting.

How do you handle this problem? Is there maybe a simple solution to this issue with little coding effort? My project plan doesn't allow me to create a complex asset handling on my own. Is there a recommendable, lightweight asset framework compatible to ZF2? I've already considered creating symlinks but I don't think this would be the best solution because it would require some additional web server configuration (FollowSymlinks) and additional maintenance work (the app is developed locally and deployed on a remote server).

Thanks in advance.

3条回答
太酷不给撩
2楼-- · 2019-04-01 02:59

There is also fourth option. Use a directory Alias in VirtualHost configuration.

查看更多
smile是对你的礼貌
3楼-- · 2019-04-01 03:04

I know this is pretty old, but I wanted to add this information for other readers.

Now there's also a module for this, which has been fully tested and is being used (and even depended on) by many modules.

Check it out here: https://github.com/RWOverdijk/AssetManager

Hope this helps.

查看更多
霸刀☆藐视天下
4楼-- · 2019-04-01 03:06

This has been discussed before in many places and it comes down to three ways to manage this.

  1. Copy and Paste the assets into the public/ directory

  2. Use symlinks

  3. Use an asset loading module like assetic

A simple solution would be to make the copying of assets part of you build process.

Another question was already asked How to merge Zend Framework 2 module public directories for info.

查看更多
登录 后发表回答