This package is abandoned and no longer maintained. The author suggests using the mirko-pagliai/cakephp-assets package instead.

Assets plugin for CakePHP

Installs: 9 501

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 1

Open Issues: 0

Type:cakephp-plugin

1.1.8 2018-04-23 15:11 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:56:09 UTC


README

Starting april 2018, this repository has been abandoned.
See instead: cakephp-assets.

Assets plugin

Software License Build Status codecov Build status

Assets is a CakePHP plugin to allows you to handle and generate assets.

It uses matthiasmullie/minify and provides a convenient helper that allows you to combine multiple asset files into one single compressed file.

Installation

You can install the plugin via composer:

$ composer require --prefer-dist mirko-pagliai/assets

NOTE: the package may require one of the latest versions version of CakePHP.
Instead, the cakephp3.2 branch is compatible with CakePHP versions from 3.2 onwards.
In this case, you can install the package as well:

$ composer require --prefer-dist mirko-pagliai/assets:dev-cakephp3.2

After installation, you have to edit APP/config/bootstrap.php to load the plugin:

Plugin::load('Assets', ['bootstrap' => true, 'routes' => true]);

For more information on how to load the plugin, please refer to the Cookbook.

By default the plugin uses the APP/tmp/assets directory to save the asset files. So you have to create the directory and make it writable:

$ mkdir tmp/assets && chmod 775 tmp/assets

If you want to use a different directory, read below.

Configuration

The plugin uses some configuration parameters and you can set them using the \Cake\Core\Configure class, before loading the plugin.

For example, you can do this at the bottom of the file APP/config/app.php of your application.

Configuration values

Configure::write('Assets.force', false);

Setting Assets.force to true, the assets will be used even if debugging is enabled.

Configure::write('Assets.target', TMP . 'assets');

Setting Assets.target, you can use another directory where the plugin will generate the assets.

How to use

You have to use only the AssetHelper. This helper provides css() and script() methods, similar to the methods provided by the HtmlHelper.

The syntax is the same, you just have to change the name helper. Example for AssetHelper::css().

echo $this->Asset->css(['one.css', 'two.css']);

This will combine and compress one.css and two.css files, creating a unique asset file, and will create a link element for CSS stylesheets, as does the method provided by the HtmlHelper.

The same also applies to the AssetHelper::script() method.

Versioning

For transparency and insight into our release cycle and to maintain backward compatibility, Assets will be maintained under the Semantic Versioning guidelines.