mheads/yii-filestorage-active-record
Composer 安装命令:
composer require mheads/yii-filestorage-active-record
包简介
README 文档
README
ActiveRecord adapter for mheads/yii-filestorage.
The package provides:
ActiveRecordRepository- aRepositoryInterfaceimplementation that stores file metadata throughyiisoft/active-record.ArFile- an ActiveRecord file entity for themh_filestorage_filetable.#[FileUpload]- an ActiveRecord event handler that uploads pending files on save and cleans old files on replace/delete.PendingUploadedFileOwnerInterfaceandPendingUploadedFileOwnerTrait- a small model-side queue for uploaded files.
Physical file storage is still handled by the core package stores, for example PublicFileSystemStore and PrivateFileSystemStore.
The file metadata table schema and DbRepository come from mheads/yii-filestorage-db, which is installed as a dependency.
Installation
composer require mheads/yii-filestorage-active-record
Also install the database driver used by your project:
composer require yiisoft/db-mysql
Before using this ActiveRecord adapter, complete the mheads/yii-filestorage-db DB adapter setup, including the DB driver and file metadata table.
For the demo product table used in examples, see example migrations.
Quick Start
use Mheads\Yii\Filestorage\ActiveRecord\ActiveRecordRepository; use Mheads\Yii\Filestorage\ActiveRecord\ArFile; use Mheads\Yii\Filestorage\Storage; use Mheads\Yii\Filestorage\StorageProvider; use Yiisoft\Db\Connection\ConnectionProvider; ConnectionProvider::set($db); $storage = new Storage( repository: new ActiveRecordRepository(ArFile::class), stores: [$publicStore], defaultStoreName: 'upload', defaultGroupName: 'products', ); StorageProvider::set($storage); $product = new Product(); $product->setPicture($uploadedFile); $product->save();
$publicStore is a core package store, for example PublicFileSystemStore.
Product should use #[FileUpload] and PendingUploadedFileOwnerTrait; see the lifecycle guide below.
ConnectionProvider::set() is required for ArFile, ActiveRecordRepository, and AR relations.
StorageProvider::set() is required for #[FileUpload] and direct file methods such as getUrl().
See the full flow in AR file upload lifecycle and 02-active-record-file-upload.php.
Documentation
License
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-06-04