Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing assets from modules in Zend Framework 2

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.

like image 472
Daniel M Avatar asked Dec 07 '22 12:12

Daniel M


2 Answers

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.

like image 166
Richard Holloway Avatar answered Dec 11 '22 09:12

Richard Holloway


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.

like image 45
Wesley Overdijk Avatar answered Dec 11 '22 08:12

Wesley Overdijk