asset management with zend framework 2
DESCRIPTION
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-2TRANSCRIPT
ZF2 Asset managementwith AssetManager module
http://www.mvassociati.it/en/gems/php/asset-management-zend-framework-2
MODULE’S ASSETS: IMAGES/JS/CSS
http://www.flickr.com/photos/tracyleephoto/8322509672
Shared between modulesLike javascript libraries, logos, buttons, CSS scripts and snippets, etc.
3
Shared between modulesLike javascript libraries, logos, buttons, CSS scripts and snippets, etc.
4
Where should they be placed?
Shared between modulesLike javascript libraries, logos, buttons, CSS scripts and snippets, etc.
5
Where should they be placed?Inside project /public folder? There is a better way…
Exclusive of a moduleLike javascript libraries, images and CSS files that are needed by a single module only
6
Exclusive of a moduleLike javascript libraries, images and CSS files that are needed by a single module only
7
Where should they be placed?
Exclusive of a moduleLike javascript libraries, images and CSS files that are needed by a single module only
8
Where should they be placed?Inside that module!
Possible approaches• Copy & paste of each file inside project
/public folder?• Use symlinks?• Tune apache to "look" the files inside
each module?
9
The way to go: AssetManager
10
AssetManagermodule
11
AssetManager
Resolvers
Filters
Cache
Assets
AssetManagermodule
12
AssetManager
Resolvers
Assets
Resolvers:allowing to define asset naming and locations
AssetManagermodule
13
AssetManager
Resolvers
FiltersAssets
Filters:allowing to make some processing before serving assets
AssetManagermodule
14
AssetManager
Resolvers
Filters
Cache
Assets
Cache:allowing to choosecaching policy
Where to put module assets?
15
all module’sassets
module.config.php
return array(
'asset_manager' => array(
'resolver_configs' => array(
'paths' => array(
__DIR__ . '/../assets',
),
),),), ...
return array(
'asset_manager' => array(
'resolver_configs' => array(
'paths' => array(
__DIR__ . '/../assets',
),
),),), ...
layout.php
echo $this->headLink()
->prependStylesheet($this->basePath() .
'/css/aCssFile.css');
module.config.php
return 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',
),),),),), ...
module.config.php
return 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',
),),),),), ...
module.config.php
layout.php
echo $this->headLink()
->prependStylesheet($this->basePath() .
'/css/merge.css');
Stefano [email protected]@mvassociati.it