ics/medias-bundle 问题修复 & 功能扩展

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

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

ics/medias-bundle

Composer 安装命令:

composer require ics/medias-bundle

包简介

File Manager for symfony

README 文档

README

Bundle for file management in symfony

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require ics/medias-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require ics/medias-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    ICS\MediaBundle\MediaBundle::class => ['all' => true],
];

Step 3: Install Database

For install database :

# Installer la base de données

php bin/console doctrine:schema:create

For update database :

# Mise a jour la base de données

php bin/console doctrine:schema:update -f

Configuration

Routing

#config/routes.yaml

#...

media_bundle:
  resource: '@MediaBundle/config/routes.yaml'
  prefix: /medias

#...

Medias configuration

You can configure relative path from the public directory. The medias files will be stored in this directory

# config/packages/medias.yaml

medias:
    path: 'medias' # Default Value

Usage

The Mediabundle propose two FormType MediaType that return One MediaFile and MediaCollectionType that retun Many MediaFile. You may precise the outputdir relative to medias path in the config.

Entity

use ICS\MediaBundle\Entity\MediaImage;

// Exemple entity

public class User
{
    /**
     * Avatar of user
     *
     * @var MediaImage
     * @ORM\ManyToOne(targetEntity=MediaImage::class, cascade={"persist","remove"})
     */
    private $avatar;

    /**
     * Gallery of user
     *
     * @var ArrayCollection
     * @ORM\ManyToMany(targetEntity=MediaImage::class, cascade={"persist","remove"})
     */
    private $gallery;

    public function __construct()
    {
        $this->gallery=new ArrayCollection();
    }
}

FormType

    //...
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        // For One file
        $builder->add('avatar',MediaType::class,[
            'outputdir' => 'user/avatar'
        ]);
        // For Many files
        $builder->add('gallery',MediaCollectionType::class,[
            'outputdir' => 'user/gallery'
        ]);
    }
    //...

You can impose limitation of type for all and size for MediaCollectionType

    //...
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        // For One file
        $builder->add('avatar',MediaType::class,[
            'outputdir' => 'user/avatar',
            'required' => false,
            'acceptedFiles' => ['image/jpeg','.jpg'],
        ]);
        // For Many files
        $builder->add('gallery',MediaCollectionType::class,[
            'outputdir' => 'user/gallery'
            'required' => false,
            'acceptedFiles' => MediaImage::$mimes
            'maxFileSize' => '1024' // 1Ko
        ]);
    }
    //...

The maxFileSize is calculated based on system capabilities and your configuration. If your configuration is higher of system capabilities, system capabilities is used.

Commands

Two commands are implemented

Integrity verification

php bin/console media:file:verify

Duplicate search

php bin/console media:search:duplicate

Integration

Adding bundle to EasyAdmin

Step 1: Add entities to dashboard

Add this MenuItems in your dashboard Controller/Admin/DashboardController.php

    // Controller/Admin/DashboardController.php
    use ICS\SsiBundle\Entity\User;
    use ICS\SsiBundle\Entity\Log;

    class DashboardController extends AbstractDashboardController
    {
        public function configureMenuItems(): iterable
        {
            // ...
            yield MenuItem::section('Medias', 'fa fa-photo-video');
            yield MenuItem::linkToCrud('Files', 'fa fa-file', MediaFile::class);
            yield MenuItem::linkToCrud('Pictures', 'fa fa-photo', MediaImage::class);
            // ...
        }
    }

Step 2: Add twig widgets to dashboard

    {% extends "@EasyAdmin/page/content.html.twig" %}

    {% block page_content %}

        {{ mediaGraphData() }}

    {% endblock %}

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固