dlds/yii2-attachments 问题修复 & 功能扩展

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

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

dlds/yii2-attachments

最新稳定版本:1.1

Composer 安装命令:

composer require dlds/yii2-attachments

包简介

Extension for file uploading and attaching to the models

README 文档

README

Extension for file uploading and attaching to the models

Installation

  1. The preferred way to install this extension is through composer.

    Either run

    php composer.phar require dlds/yii2-attachments "*"
    

    or add

    "dlds/yii2-attachments": "*"
    

    to the require section of your composer.json file.

  2. Apply migrations

    php yii migrate/up --migrationPath=@vendor/dlds/yii2-attachments/migrations
    
  3. Add module to config/main.php

    'modules' => [
    	...
    	'attachments' => [
    		'class' => dlds\attachments\Module::className(),
    		'tempPath' => '@app/uploads/temp',
    		'storePath' => '@app/uploads/store'
    	]
    	...
    ]
  4. Attach behavior to your model (be sure that your model has "id" property)

    public function behaviors()
    {
    	return [
    		...
    		'attachmentBehavior' => [
    		'class' => \dlds\attachments\behaviors\AttachmentBehavior::className()
    		]
    		...
    	];
    }
  5. Make sure that you have added 'enctype' => 'multipart/form-data' to the ActiveForm options

Usage

  1. In the form.php of your model add file input

    <?= \kartik\file\FileInput::widget([
    	'name' => 'file[]',
    	'id' => 'file-input',
    	'options' => [
    		'multiple' => true, // false if you want to allow upload a single file
    	],
    	'pluginOptions' => [
    		'uploadUrl' => yii\helpers\Url::toRoute('/attachments/file/upload'), // remove this if you don't want to use AJAX uploading 
    		'initialPreview' => $model->isNewRecord ? [] : $model->getInitialPreview(),
    		'initialPreviewConfig' => $model->isNewRecord ? [] : $model->getInitialPreviewConfig(),
    		// other options
    	]
    ]); ?>
  2. Use widget to show all attachments of the model in the view.php

    <?= \dlds\attachments\components\AttachmentsTable::widget(['model' => $model]) ?>
  3. (Optional) Add onclick action to your submit button that uploads all files before submitting form

    <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', [
    	'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',
    	'onclick' => "$('#file-input').fileinput('upload');"
    ]) ?>

Change log

  • Feb 2, 2015 - Fix: all attached files will be deleted with the model.
  • Feb 1, 2015 - AJAX or basic upload.
  • Jan 30, 2015 - Several previews of images and other files, fix of required packages.
  • Jan 29, 2015 - First version with basic uploading and previews.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 57
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-4-Clause
  • 更新时间: 2015-02-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固