Asset management with Zend Framework 2

7,034 views

Published on

One of the first issues a developer runs into when dealing with ZF2 modules is how to arrange assets between modules. This presentation covers such issue.

More can be found on this blog post: http://www.mvassociati.it/en/gems/php/asset-management-zend-framework-2

Published in: Technology

Asset management with Zend Framework 2

  1. 1. ZF2 Asset management with AssetManager modulehttp://www.mvassociati.it/en/gems/php/asset-management-zend-framework-2
  2. 2. MODULE’S ASSETS: IMAGES/JS/CSShttp://www.flickr.com/photos/tracyleephoto/8322509672
  3. 3. Shared between modules Like javascript libraries, logos, buttons, CSS scripts and snippets, etc.3
  4. 4. Shared between modules Like javascript libraries, logos, buttons, CSS scripts and snippets, etc. Where should they be placed?4
  5. 5. Shared between modules Like javascript libraries, logos, buttons, CSS scripts and snippets, etc. Where should they be placed? Inside project /public folder? There is a better way…5
  6. 6. Exclusive of a module Like javascript libraries, images and CSS files that are needed by a single module only6
  7. 7. Exclusive of a module Like javascript libraries, images and CSS files that are needed by a single module only Where should they be placed?7
  8. 8. Exclusive of a module Like javascript libraries, images and CSS files that are needed by a single module only Where should they be placed? Inside that module!8
  9. 9. Possible approaches • Copy & paste of each file inside project /public folder? • Use symlinks? • Tune apache to "look" the files inside each module?9
  10. 10. The way to go: AssetManager10
  11. 11. AssetManagermodule Resolvers Assets Asset Filters Manager Cache11
  12. 12. AssetManagermodule Resolvers Assets Asset ManagerResolvers:allowing to define asset naming and locations12
  13. 13. AssetManagermodule Resolvers Assets Asset Filters ManagerFilters:allowing to make some processingbefore serving assets13
  14. 14. AssetManagermodule Resolvers Assets Asset Filters ManagerCache:allowing to choose Cachecaching policy14
  15. 15. Where to put module assets? all module’s assets15
  16. 16. module.config.phpreturn array( asset_manager => array( resolver_configs => array( paths => array( __DIR__ . /../assets, ),),),), ...
  17. 17. module.config.phpreturn array( asset_manager => array( resolver_configs => array( paths => array( __DIR__ . /../assets, ),),),), ... layout.php echo $this->headLink() ->prependStylesheet($this->basePath() . /css/aCssFile.css);
  18. 18. module.config.phpreturn array(asset_manager => array( resolver_configs => array( map => array( css/main.css => __DIR__./../assets/css/main.css, css/custom1.css => __DIR__./../assets/css/custom1.css, ), collections => array( css/merge.css => array( css/main.css,css/custom1.css,),),),),), ...
  19. 19. module.config.phpreturn array(asset_manager => array( resolver_configs => array( map => array( css/main.css => __DIR__./../assets/css/main.css, css/custom1.css => __DIR__./../assets/css/custom1.css, ), collections => array( css/merge.css => array( css/main.css,css/custom1.css,),),),),), ... layout.php echo $this->headLink() ->prependStylesheet($this->basePath() . /css/merge.css);
  20. 20. Stefano Valle@stefanovalles.valle@mvassociati.it

×