PHP code example of ics / medias-bundle

1. Go to this page and download the library: Download ics/medias-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ics / medias-bundle example snippets


// config/bundles.php

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


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();
    }
}


    //...
    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'
        ]);
    }
    //...

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

    // 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);
            // ...
        }
    }
bash
# Installer la base de données

php bin/console doctrine:schema:create

bash

php bin/console media:file:verify