arter /amos-attachments
该包最新版本(1.6.0)没有提供许可证信息。
文件上传和附件模型扩展
1.6.0
2024-04-03 08:50 UTC
Requires
- php: >=5.4.0
- arter/amos-core: ^1.17.0
- bower-asset/jquery-cropper: ^1.0
- himiklab/yii2-colorbox-widget: *
- kartik-v/yii2-widget-fileinput: 1.0.6
- ralouphie/mimey: ^2.1.0
- uitrick/yii2-widget-upload-crop: ^1.0.0
- yiisoft/yii2: ^2.0.0
- yiisoft/yii2-imagine: ^2.1.0
- yiisoft/yii2-jui: ^2.0
- yurkinx/yii2-image: *
Requires (Dev)
- phpunit/dbunit: ~1.0
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-07 09:49:33 UTC
README
文件上传和附件模型扩展
演示
您可以在krajee网站上查看演示
安装
- 通过composer安装此扩展是首选方式。
运行以下命令
composer require arter/amos-attachments
或者在您的composer.json
文件的require部分添加以下内容
"arter/amos-attachments": ">=1.0"
- 将模块添加到您的common主配置中
<?php
'aliases' => [
'@file' => dirname(__DIR__),
],
'modules' => [
'attachments' => [
'class' => 'arter\amos\attachments\FileModule',
'webDir' => 'files',
'tempPath' => '@common/uploads/temp',
'storePath' => '@common/uploads/store',
// 'tableName' => '{{%attach_file}}' // Optional, default to 'attach_file'
],
],
同时,将这些行添加到您的控制台配置中
<?php
'controllerMap' => [
'attachments' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => '@amos_attachments/migrations'
],
],
- 应用迁移
php yii migrate/up --migrationPath=@vendor/arter/amos-attachments/src/migrations
- 将行为附加到您的模型上(请确保您的模型具有“id”属性)
<?php
use yii\helpers\ArrayHelper;
/**
* Adding the file behavior
*/
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'fileBehavior' => [
'class' => \file\behaviors\FileBehavior::className()
]
]);
}
/**
* Add the new fields to the file behavior
*/
public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['my_field_multiple_files', 'my_field_single_file'], 'file'],
]);
}
确保您已经将
'enctype' => 'multipart/form-data'
添加到ActiveForm选项中确保您已在模块规则中指定了
maxFiles
,并在AttachmentsInput
上指定了maxFileCount
到您想要的数字您现在可以使用它了,查看如何使用