Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

php - How to merge Zend Framework 2 module public directories

Some zf2 modules have public directories for distribution of resources such as js/css/images. What is best practice for making these resouces available to the applicaiton?

I would like it so that these resources were automatically available through http://mysite.com/[moduleName]/. For example,

root/public/js/sitescript.js --> http:\mysite.comjssitescript.js

root/module/mymodule/public/js/modulescript.js --> http:\mysite.commymodulejsmodulescript.js

root/vendor/vendormodule/public/js/vendorscript.js --> http:\mysite.comvendormodulejsvendorscript.js

Should these resources be copied to the root/public directory? Manual copying will be painful, and I doubt an automated build process to merge the directories would be very practial either.

Perhaps there is some magic that can be worked with httpd.conf or .htaccess?

Perhaps symlinks are the solution? But, symlinks are not straight forward to get going on a Windows platform, and would need to be created manually for each individual module.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are 4 ways of handling this:

  1. Symlinking assets in the public/ directory
  2. Copy-pasting assets from the modules to the public/ directory
  3. Using a particular Virtual Host Configuration (or generally web-server configuration)
  4. Use an asset-manager module, such as one of the following:

    • AssetManager - backed by assetic - merges assets at runtime, has caching for production environments and filters for CSS/JS minification and LESS/SASS conversion, allows exposing of assets from directories in the modules themselves.
    • zf2-assetic-module - backed by assetic - handles CSS/JS minification and LESS/SASS conversion at runtime
    • BaconAssetLoader - exposes assets from modules by deploying them in the public/ dir at deploy time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...