20
ZF2 Asset management with AssetManager module http:// www.mvassociati.it/en/gems/php/asset-management-zend-framework-2

Asset management with Zend Framework 2

Embed Size (px)

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-2

Citation preview

Page 1: Asset management with Zend Framework 2

ZF2 Asset managementwith AssetManager module

http://www.mvassociati.it/en/gems/php/asset-management-zend-framework-2

Page 2: Asset management with Zend Framework 2

MODULE’S ASSETS: IMAGES/JS/CSS

http://www.flickr.com/photos/tracyleephoto/8322509672

Page 3: Asset management with Zend Framework 2

Shared between modulesLike javascript libraries, logos, buttons, CSS scripts and snippets, etc.

3

Page 4: Asset management with Zend Framework 2

Shared between modulesLike javascript libraries, logos, buttons, CSS scripts and snippets, etc.

4

Where should they be placed?

Page 5: Asset management with Zend Framework 2

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…

Page 6: Asset management with Zend Framework 2

Exclusive of a moduleLike javascript libraries, images and CSS files that are needed by a single module only

6

Page 7: Asset management with Zend Framework 2

Exclusive of a moduleLike javascript libraries, images and CSS files that are needed by a single module only

7

Where should they be placed?

Page 8: Asset management with Zend Framework 2

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!

Page 9: Asset management with Zend Framework 2

Possible approaches• Copy & paste of each file inside project

/public folder?• Use symlinks?• Tune apache to "look" the files inside

each module?

9

Page 10: Asset management with Zend Framework 2

The way to go: AssetManager

10

Page 11: Asset management with Zend Framework 2

AssetManagermodule

11

AssetManager

Resolvers

Filters

Cache

Assets

Page 12: Asset management with Zend Framework 2

AssetManagermodule

12

AssetManager

Resolvers

Assets

Resolvers:allowing to define asset naming and locations

Page 13: Asset management with Zend Framework 2

AssetManagermodule

13

AssetManager

Resolvers

FiltersAssets

Filters:allowing to make some processing before serving assets

Page 14: Asset management with Zend Framework 2

AssetManagermodule

14

AssetManager

Resolvers

Filters

Cache

Assets

Cache:allowing to choosecaching policy

Page 15: Asset management with Zend Framework 2

Where to put module assets?

15

all module’sassets

Page 16: Asset management with Zend Framework 2

module.config.php

return array(

'asset_manager' => array(

'resolver_configs' => array(

'paths' => array(

__DIR__ . '/../assets',

),

),),), ...

Page 17: Asset management with Zend Framework 2

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

Page 18: Asset management with Zend Framework 2

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

Page 19: Asset management with Zend Framework 2

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');

Page 20: Asset management with Zend Framework 2

Stefano [email protected]@mvassociati.it