PHPackages                             passchn/cakephp-assets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. passchn/cakephp-assets

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

passchn/cakephp-assets
======================

Asset management plugin for CakePHP

v0.6.1(4mo ago)29861[1 issues](https://github.com/brandcom/cakephp-assets/issues)1MITPHPPHP &gt;=8.2CI failing

Since Jan 21Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/brandcom/cakephp-assets)[ Packagist](https://packagist.org/packages/passchn/cakephp-assets)[ RSS](/packages/passchn-cakephp-assets/feed)WikiDiscussions cake5 Synced 3w ago

READMEChangelog (10)Dependencies (8)Versions (37)Used By (1)

Assets plugin for CakePHP
=========================

[](#assets-plugin-for-cakephp)

What the plugin does
--------------------

[](#what-the-plugin-does)

This plugin helps you to manage backend Assets which can be of any filetype. Assets are saved in a non-public folder and are handled by an AssetsTable.

You can create AssetEntities with useful methods:

### General methods

[](#general-methods)

- Check if the uploaded file still is there: `$asset->exists() // true or false`
- `$asset->getFileSizeInfo()` prints a human-readable filesize.
- Get a link to the AssetsController::download() (Admin-prefixed): `$asset->getDownloadLink()`

### Image rendering

[](#image-rendering)

- Call `echo $asset->getImage()->scaleWidth(350)->toWebP()->addCSS('my-class')` to render a WebP-thumbnail as HTML.
- The rendered image will be saved in `webroot/img/modified` depending on the modifications and passed options.
- Pass your custom InterventionImage Filters through `ImageAsset::applyFilter()`
- You can call any InterventionImage API method through `ImageAsset::modify()`

### CSV preview

[](#csv-preview)

- You can use the `TextAssetPreviewHelper` to render tables from CSV-files.
- Loop through rows in a csv-Asset: `foreach ($asset->getReader()->getRecords() as $row) ...`

### Alibi-properties for any model

[](#alibi-properties-for-any-model)

- `$asset` can be `$user->image`, `$company->logo` or your latest CSV import. Just configure a `belongsTo` relation on your model and set the ClassName.

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).

The recommended way to install composer packages is:

```
composer require passchn/cakephp-assets

```

Load the plugin:

```
 bin/cake plugin load Assets

```

Run the Migrations to create the plugin tables:

```
bin/cake migrations migrate -p Assets

```

Now you should have an `assets_assets` and an `assets_phinxlog` table in your database.

> Having issues? Check out [this demo app](https://github.com/passchn/cakephp-assets-example-app/) or the [single commits](https://github.com/passchn/cakephp-assets-example-app/commits/main) to see how to setup the plugin.

CakePHP Version Map
-------------------

[](#cakephp-version-map)

There is no version 1 of this plugin yet. To use it within your project, check the version map:

Plugin VersionCakePHP Versiondev-cake3CakePHP 3.x^0 -&gt; ^0.4CakePHP 4.x^0.5CakePHP 5.xUploading Files
---------------

[](#uploading-files)

### AssetsController

[](#assetscontroller)

You can directly upload files using the AssetsController. By default, you can access the index, view, and edit-methods through an `Admin` prefix: `your-app.test/admin/assets/assets`

### Use Alibi names

[](#use-alibi-names)

You can use the Assets table to upload files from any model, say you have a `users` table and need a user image:

1. Create a field `userimage_id` in the `users` table as nullable `char(36)` (UUID).
2. Run the migrations: `bin/cake bake users`
3. Now you need to tell CakePHP that your `Userimage` is not a real Entity, but comes from the `Assets.AssetsTable` table:

```
in \App\Model\Table\Users:

$this->belongsTo('Userimages')
    ->setForeignKey('userimage_id')
    ->setClassName('Assets.Assets');

```

> This does not work anymore. The `cakephp-bake` plugin from version `2.8` onwards seems to detect that you don't actually have a `userimages` table and will not assume a `belongsTo` relation. You will have to write the code yourself or downgrade to version `2.7`.

You can now put an upload field for your Userimage e.g. in `templates/Users/edit.php`:

```

    ...
    ...

    ...

```

In order for this to work, the relation should be set properly, e.g. through `bin/cake bake users`, so that CakePHP knows that your `$user->userimage` is an `Asset` Entity. Note that you have to contain `Userimages` in your Controller or Table's finder methods:

```
$users = $this->Users->find()->contain([
        'Userimages',
        'Addresses,
        '...
    ]);

$image = $users->first()->userimage?->getImage();

```

The AssetsTable does not know which model the uploaded file belongs to. You can use the `title`, `description`, or `category` field to keep track of that.

To do this, you can inject custom behaviors into the AssetsTable to hook into Event Handlers (e.g., set the `title` on `beforeSave()`), or to create custom finder methods, e.g. by your defined categories.

In your config file `app.php`, `app_local.php`, or `app_assets.php`, you can override the [default settings](https://github.com/passchn/cakephp-assets/blob/master/config/app_assets.php) and add custom Behaviors.

File manipulation
-----------------

[](#file-manipulation)

### Images

[](#images)

If an Asset is an image (the MimeType starts with `image/*`), you can call

```
$asset->getImage();

```

This returns an instance of the `Assets\Utilities\ImageAsset` class, which offers a wrapper API for `ImagineImage`.

For example, you can call:

```
echo $asset->getImage()->scaleWidth(350)->toWebP()->getPath()

```

This will generate a scaled version of your original file, converted to WebP, and return the relative path (in `/webroot`) to the file.

You might want to output html directly:

```

```

This will call the `ImageAsset::__toString()` method and will return HTML with your set class, an alt-parameter with the Asset's title and correct `width` and `height` params.

Image manipulation is done through Intervention with GD as default, but you can enable imagick through your app.php config.

#### Rendering of `` elements

[](#rendering-of-picture-elements)

Load the PictureHelper in your `AppView.php`:

```
$this->loadHelper('Assets.Picture');

```

In a template, pass an `ImageAsset` to the Helper as well as an array of widths and params:

```

```

Feedback, Bugs, and Feature Requests
------------------------------------

[](#feedback-bugs-and-feature-requests)

This plugin was no plugin from the beginning and we are working on making it usable now among different CakePHP installations.

As this package is in early development as a plugin, we don't expect it to fit in for a lot of use cases right now.

If you have questions or problems with the plugin, open an Issue on GitHub.

You can also contact me via email:

Packages this plugin uses
-------------------------

[](#packages-this-plugin-uses)

Besides CakePHP, the plugin depends on the following packages:

```
"josegonzalez/cakephp-upload": "^6.0",
"league/csv": "^9.8",
"nette/utils": "^3.2 || ^4.0",
"intervention/image": "^2.7"

```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance73

Regular maintenance activity

Popularity20

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Recently: every ~214 days

Total

28

Last Release

149d ago

PHP version history (4 changes)v0.0.1PHP &gt;=8.0

v0.1.2PHP &gt;=7.4

v0.5.0PHP &gt;=8.1

v0.6.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77938819?v=4)[Pascal Schneider](/maintainers/passchn)[@passchn](https://github.com/passchn)

---

Top Contributors

[![passchn](https://avatars.githubusercontent.com/u/77938819?v=4)](https://github.com/passchn "passchn (138 commits)")[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (14 commits)")[![jcsiegrist](https://avatars.githubusercontent.com/u/33805?v=4)](https://github.com/jcsiegrist "jcsiegrist (5 commits)")

---

Tags

cakephpfilesimage-manipulationimage-resizethumbnailsuploadswebp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/passchn-cakephp-assets/health.svg)

```
[![Health](https://phpackages.com/badges/passchn-cakephp-assets/health.svg)](https://phpackages.com/packages/passchn-cakephp-assets)
```

###  Alternatives

[azuracast/azuracast

The AzuraCast self-hosted web radio station management suite.

3.9k27.8k](/packages/azuracast-azuracast)[october/rain

October Rain Library

1581.7M73](/packages/october-rain)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5255.7M110](/packages/symplify-monorepo-builder)[nette/component-model

⚛ Nette Component Model

28716.8M101](/packages/nette-component-model)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

749284.3k35](/packages/civicrm-civicrm-core)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

333972.2k49](/packages/dereuromark-cakephp-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
