badbreze / yii2-attachments
1.2.12
2017-02-21 15:41 UTC
Requires
- php: >=5.4.0
- badbreze/yii2-widget-fileinput: >=2.0
- himiklab/yii2-colorbox-widget: *
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-jui: ^2.0
- yurkinx/yii2-image: *
Requires (Dev)
- phpunit/dbunit: ~1.0
- phpunit/phpunit: ~4.0
README
文件上传和附加到模型扩展
此分支的目标是实现一些缺失的功能,例如多字段和简化安装。
演示
您可以在krajee网站上查看演示。
安装
- 安装此扩展的首选方式是通过composer。
运行以下命令
composer require badbreze/yii2-attachments
或
"badbreze/yii2-attachments": ">=1.2.0"
将以下内容添加到您的composer.json
文件的require部分。
- 将模块添加到您的主配置
<?php 'aliases' => [ '@file' => dirname(__DIR__), ], 'modules' => [ 'file' => [ 'class' => 'file\FileModule', 'webDir' => 'files', 'tempPath' => '@common/uploads/temp', 'storePath' => '@common/uploads/store', 'tableName' => '{{%attach_file}}' // Optional, default to 'attach_file' ], ],
同样,将这些行添加到您的控制台配置
<?php 'controllerMap' => [ 'file' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => '@file/migrations' ], ],
- 应用迁移
php yii migrate/up --migrationPath=@vendor/badbreze/yii2-attachments/src/migrations
- 将行为附加到您的模型(确保您的模型有"ID"属性)
<?php use yii\helpers\ArrayHelper; /** * Declare file fields */ public $my_field_multiple_files; public $my_field_single_file; /** * 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
为所需的数量 -
您现在可以开始使用了,查看如何使用