mheads/yii-filestorage-active-record 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 - a RepositoryInterface implementation that stores file metadata through yiisoft/active-record.
  • ArFile - an ActiveRecord file entity for the mh_filestorage_file table.
  • #[FileUpload] - an ActiveRecord event handler that uploads pending files on save and cleans old files on replace/delete.
  • PendingUploadedFileOwnerInterface and PendingUploadedFileOwnerTrait - 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

BSD-3-Clause

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-06-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固